'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 LoginPacientePage() { 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 paciente const success = await login(credentials.email, credentials.password, 'paciente') if (success) { // Redirecionar para a página do paciente router.push('/paciente') } } catch (err) { console.error('[LOGIN-PACIENTE] Erro no login:', err) if (err instanceof AuthenticationError) { // Verificar se é erro de credenciais inválidas (pode ser email não confirmado) if (err.code === '400' || err.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(err.message) } } else { setError('Erro inesperado. Tente novamente.') } } finally { setLoading(false) } } // Auto-cadastro foi removido (UI + client-side endpoint call) return (
Acesse sua área pessoal e gerencie suas consultas