'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 LoginAdminPage() { 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.MouseEvent) => { e.preventDefault(); console.log('[LOGIN-DEBUG] 1. handleLogin iniciado.'); setLoading(true); setError(''); try { console.log('[LOGIN-DEBUG] 2. Chamando a função de login do useAuth...'); const success = await login(credentials.email, credentials.password, 'administrador'); console.log('[LOGIN-DEBUG] 3. A função de login retornou:', success); if (success) { console.log('[LOGIN-DEBUG] 4. Sucesso! Redirecionando para /dashboard...'); window.location.href = '/dashboard'; } else { console.log('[LOGIN-DEBUG] 4b. A função de login retornou um valor falso, mas não lançou erro.'); setError('Ocorreu uma falha inesperada no login.'); } } catch (err) { console.log('[LOGIN-DEBUG] 5. Ocorreu um erro (catch).'); console.error('[LOGIN-ADMIN] Erro no login:', err); if (err instanceof AuthenticationError) { setError(err.message); } else { setError('Erro inesperado. Tente novamente.'); } } finally { console.log('[LOGIN-DEBUG] 6. Bloco finally executado.'); setLoading(false); } } return (

Login Administrador de Clínica

Entre com suas credenciais para acessar o sistema administrativo

Acesso Administrativo
e.preventDefault()} className="space-y-6">
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} )}
) }