From 199a3197bef81ea63d72c857a11575543700fede Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jo=C3=A3o=20Gustavo?=
<166467972+JoaoGustavo-dev@users.noreply.github.com>
Date: Thu, 16 Oct 2025 22:20:03 -0300
Subject: [PATCH] add-magic-link-endpoint
---
susconecta/app/login-paciente/page.tsx | 44 +++++++++++++++++++++++++
susconecta/app/login/page.tsx | 45 ++++++++++++++++++++++++++
susconecta/lib/api.ts | 43 ++++++++++++++++++------
3 files changed, 123 insertions(+), 9 deletions(-)
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}
+
+ )}
+
+
+