diff --git a/susconecta/app/login-paciente/page.tsx b/susconecta/app/login-paciente/page.tsx index 75e4b2e..3747c61 100644 --- a/susconecta/app/login-paciente/page.tsx +++ b/susconecta/app/login-paciente/page.tsx @@ -3,6 +3,7 @@ import { useState } from 'react' import { useRouter } from 'next/navigation' import Link from 'next/link' import { useAuth } from '@/hooks/useAuth' +import { sendMagicLink } from '@/lib/api' import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card' @@ -12,6 +13,9 @@ import { AuthenticationError } from '@/lib/auth' export default function LoginPacientePage() { const [credentials, setCredentials] = useState({ email: '', password: '' }) const [error, setError] = useState('') + const [magicMessage, setMagicMessage] = useState('') + const [magicError, setMagicError] = useState('') + const [magicLoading, setMagicLoading] = useState(false) const [loading, setLoading] = useState(false) const router = useRouter() const { login } = useAuth() @@ -51,6 +55,27 @@ export default function LoginPacientePage() { } } + const handleSendMagicLink = async () => { + if (!credentials.email) { + setMagicError('Por favor, preencha o email antes de solicitar o magic link.') + return + } + + setMagicLoading(true) + setMagicError('') + setMagicMessage('') + + try { + const res = await sendMagicLink(credentials.email, { emailRedirectTo: `${window.location.origin}/` }) + setMagicMessage(res?.message ?? 'Magic link enviado. Verifique seu email.') + } catch (err: any) { + console.error('[MAGIC-LINK PACIENTE] erro ao enviar:', err) + setMagicError(err?.message ?? String(err)) + } finally { + setMagicLoading(false) + } + } + return (
@@ -115,6 +140,25 @@ export default function LoginPacientePage() { {loading ? 'Entrando...' : 'Entrar na Minha Área'} +
+
Ou entre usando um magic link (sem senha)
+ + {magicError && ( + + {magicError} + + )} + + {magicMessage && ( + + {magicMessage} + + )} + + +
+
+
Ou entre usando um magic link (sem senha)
+ + {magicError && ( + + {magicError} + + )} + + {magicMessage && ( + + {magicMessage} + + )} + + +