"use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; import Link from "next/link"; import { useAuth } from "@/hooks/useAuth"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Alert, AlertDescription } from "@/components/ui/alert"; import { AuthenticationError } from "@/lib/auth"; export default function LoginPage() { const [credentials, setCredentials] = useState({ email: "", password: "" }); const [error, setError] = useState(""); const [loading, setLoading] = useState(false); const router = useRouter(); const { login } = useAuth(); const handleLogin = async (e: React.FormEvent) => { e.preventDefault(); setLoading(true); setError(""); try { // Tentar fazer login usando o contexto com tipo profissional const success = await login( credentials.email, credentials.password, "profissional", ); if (success) { console.log( "[LOGIN-PROFISSIONAL] Login bem-sucedido, redirecionando...", ); // Redirecionamento direto - solução que funcionou window.location.href = "/profissional"; } } catch (error_) { console.error("[LOGIN-PROFISSIONAL] Erro no login:", error_); if (error_ instanceof AuthenticationError) { // Verificar se é erro de credenciais inválidas (pode ser email não confirmado) if ( error_.code === "400" || error_.details?.error_code === "invalid_credentials" ) { setError( "⚠️ Email ou senha incorretos. Se você acabou de se cadastrar, " + "verifique sua caixa de entrada e clique no link de confirmação " + "que foi enviado para " + credentials.email, ); } else { setError(error_.message); } } else { setError("Erro inesperado. Tente novamente."); } } finally { setLoading(false); } }; return (

Login Profissional de Saúde

Entre com suas credenciais para acessar o sistema

Acesso ao Sistema
setCredentials({ ...credentials, email: e.target.value }) } required className="mt-1" disabled={loading} />
setCredentials({ ...credentials, password: e.target.value }) } required className="mt-1" disabled={loading} />
{error && ( {error} )}
); }