develop #83
17
susconecta/app/(auth)/login-admin/page-new.tsx
Normal file
17
susconecta/app/(auth)/login-admin/page-new.tsx
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
'use client'
|
||||||
|
import { useEffect } from 'react'
|
||||||
|
import { useRouter } from 'next/navigation'
|
||||||
|
|
||||||
|
export default function LoginAdminRedirect() {
|
||||||
|
const router = useRouter()
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
router.replace('/login')
|
||||||
|
}, [router])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="min-h-screen flex items-center justify-center">
|
||||||
|
<p>Redirecionando para a página de login...</p>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@ -1,128 +1,17 @@
|
|||||||
'use client'
|
'use client'
|
||||||
import { useState } from 'react'
|
import { useEffect } from 'react'
|
||||||
import { useRouter } from 'next/navigation'
|
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() {
|
export default function LoginAdminRedirect() {
|
||||||
const [credentials, setCredentials] = useState({ email: '', password: '' })
|
|
||||||
const [error, setError] = useState('')
|
|
||||||
|
|
||||||
const [loading, setLoading] = useState(false)
|
|
||||||
const router = useRouter()
|
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 administrador
|
|
||||||
const success = await login(credentials.email, credentials.password, 'administrador')
|
|
||||||
|
|
||||||
if (success) {
|
|
||||||
console.log('[LOGIN-ADMIN] Login bem-sucedido, redirecionando...')
|
|
||||||
|
|
||||||
// Redirecionamento direto - solução que funcionou
|
|
||||||
window.location.href = '/dashboard'
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
console.error('[LOGIN-ADMIN] Erro no login:', err)
|
|
||||||
|
|
||||||
if (err instanceof AuthenticationError) {
|
|
||||||
setError(err.message)
|
|
||||||
} else {
|
|
||||||
setError('Erro inesperado. Tente novamente.')
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
setLoading(false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
router.replace('/login')
|
||||||
|
}, [router])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="min-h-screen flex items-center justify-center bg-background py-12 px-4 sm:px-6 lg:px-8">
|
<div className="min-h-screen flex items-center justify-center">
|
||||||
<div className="max-w-md w-full space-y-8">
|
<p>Redirecionando para a página de login...</p>
|
||||||
<div className="text-center">
|
|
||||||
<h2 className="mt-6 text-3xl font-extrabold text-foreground">
|
|
||||||
Login Administrador de Clínica
|
|
||||||
</h2>
|
|
||||||
<p className="mt-2 text-sm text-muted-foreground">
|
|
||||||
Entre com suas credenciais para acessar o sistema administrativo
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<Card>
|
|
||||||
<CardHeader>
|
|
||||||
<CardTitle className="text-center">Acesso Administrativo</CardTitle>
|
|
||||||
</CardHeader>
|
|
||||||
<CardContent>
|
|
||||||
<form onSubmit={handleLogin} className="space-y-6">
|
|
||||||
<div>
|
|
||||||
<label htmlFor="email" className="block text-sm font-medium text-foreground">
|
|
||||||
Email
|
|
||||||
</label>
|
|
||||||
<Input
|
|
||||||
id="email"
|
|
||||||
type="email"
|
|
||||||
placeholder="Digite seu email"
|
|
||||||
value={credentials.email}
|
|
||||||
onChange={(e) => setCredentials({...credentials, email: e.target.value})}
|
|
||||||
required
|
|
||||||
className="mt-1"
|
|
||||||
disabled={loading}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<label htmlFor="password" className="block text-sm font-medium text-foreground">
|
|
||||||
Senha
|
|
||||||
</label>
|
|
||||||
<Input
|
|
||||||
id="password"
|
|
||||||
type="password"
|
|
||||||
placeholder="Digite sua senha"
|
|
||||||
value={credentials.password}
|
|
||||||
onChange={(e) => setCredentials({...credentials, password: e.target.value})}
|
|
||||||
required
|
|
||||||
className="mt-1"
|
|
||||||
disabled={loading}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{error && (
|
|
||||||
<Alert variant="destructive">
|
|
||||||
<AlertDescription>{error}</AlertDescription>
|
|
||||||
</Alert>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<Button
|
|
||||||
type="submit"
|
|
||||||
className="w-full cursor-pointer"
|
|
||||||
disabled={loading}
|
|
||||||
>
|
|
||||||
{loading ? 'Entrando...' : 'Entrar no Sistema Administrativo'}
|
|
||||||
</Button>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
|
|
||||||
<div className="mt-4 text-center">
|
|
||||||
<Button variant="outline" asChild className="w-full hover:bg-primary! hover:text-white! hover:border-primary! transition-all duration-200">
|
|
||||||
<Link href="/">
|
|
||||||
Voltar ao Início
|
|
||||||
</Link>
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -1,138 +1,17 @@
|
|||||||
'use client'
|
'use client'
|
||||||
import { useState } from 'react'
|
import { useEffect } from 'react'
|
||||||
import { useRouter } from 'next/navigation'
|
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() {
|
export default function LoginPacienteRedirect() {
|
||||||
const [credentials, setCredentials] = useState({ email: '', password: '' })
|
|
||||||
const [error, setError] = useState('')
|
|
||||||
|
|
||||||
const [loading, setLoading] = useState(false)
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const { login } = useAuth()
|
|
||||||
|
|
||||||
const handleLogin = async (e: React.FormEvent) => {
|
useEffect(() => {
|
||||||
e.preventDefault()
|
router.replace('/login')
|
||||||
setLoading(true)
|
}, [router])
|
||||||
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 (
|
return (
|
||||||
<div className="min-h-screen flex items-center justify-center bg-background py-12 px-4 sm:px-6 lg:px-8">
|
<div className="min-h-screen flex items-center justify-center">
|
||||||
<div className="max-w-md w-full space-y-8">
|
<p>Redirecionando...</p>
|
||||||
<div className="text-center">
|
|
||||||
<h2 className="mt-6 text-3xl font-extrabold text-foreground">
|
|
||||||
Sou Paciente
|
|
||||||
</h2>
|
|
||||||
<p className="mt-2 text-sm text-muted-foreground">
|
|
||||||
Acesse sua área pessoal e gerencie suas consultas
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<Card>
|
|
||||||
<CardHeader>
|
|
||||||
<CardTitle className="text-center">Entrar como Paciente</CardTitle>
|
|
||||||
</CardHeader>
|
|
||||||
<CardContent>
|
|
||||||
<form onSubmit={handleLogin} className="space-y-6">
|
|
||||||
<div>
|
|
||||||
<label htmlFor="email" className="block text-sm font-medium text-foreground">
|
|
||||||
Email
|
|
||||||
</label>
|
|
||||||
<Input
|
|
||||||
id="email"
|
|
||||||
type="email"
|
|
||||||
placeholder="Digite seu email"
|
|
||||||
value={credentials.email}
|
|
||||||
onChange={(e) => setCredentials({...credentials, email: e.target.value})}
|
|
||||||
required
|
|
||||||
className="mt-1"
|
|
||||||
disabled={loading}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<label htmlFor="password" className="block text-sm font-medium text-foreground">
|
|
||||||
Senha
|
|
||||||
</label>
|
|
||||||
<Input
|
|
||||||
id="password"
|
|
||||||
type="password"
|
|
||||||
placeholder="Digite sua senha"
|
|
||||||
value={credentials.password}
|
|
||||||
onChange={(e) => setCredentials({...credentials, password: e.target.value})}
|
|
||||||
required
|
|
||||||
className="mt-1"
|
|
||||||
disabled={loading}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{error && (
|
|
||||||
<Alert variant="destructive">
|
|
||||||
<AlertDescription>{error}</AlertDescription>
|
|
||||||
</Alert>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<Button
|
|
||||||
type="submit"
|
|
||||||
className="w-full cursor-pointer"
|
|
||||||
disabled={loading}
|
|
||||||
>
|
|
||||||
{loading ? 'Entrando...' : 'Entrar na Minha Área'}
|
|
||||||
</Button>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
|
|
||||||
<div className="mt-4 text-center">
|
|
||||||
<Button variant="outline" asChild className="w-full hover:bg-primary! hover:text-white! hover:border-primary! transition-all duration-200">
|
|
||||||
<Link href="/">
|
|
||||||
Voltar ao Início
|
|
||||||
</Link>
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
{/* Auto-cadastro UI removed */}
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
17
susconecta/app/(auth)/login-profissional/page.tsx
Normal file
17
susconecta/app/(auth)/login-profissional/page.tsx
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
'use client'
|
||||||
|
import { useEffect } from 'react'
|
||||||
|
import { useRouter } from 'next/navigation'
|
||||||
|
|
||||||
|
export default function LoginProfissionalRedirect() {
|
||||||
|
const router = useRouter()
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
router.replace('/login')
|
||||||
|
}, [router])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="min-h-screen flex items-center justify-center">
|
||||||
|
<p>Redirecionando para a página de login...</p>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@ -12,10 +12,23 @@ import { AuthenticationError } from '@/lib/auth'
|
|||||||
export default function LoginPage() {
|
export default function LoginPage() {
|
||||||
const [credentials, setCredentials] = useState({ email: '', password: '' })
|
const [credentials, setCredentials] = useState({ email: '', password: '' })
|
||||||
const [error, setError] = useState('')
|
const [error, setError] = useState('')
|
||||||
|
|
||||||
const [loading, setLoading] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const { login } = useAuth()
|
const { login, user } = useAuth()
|
||||||
|
|
||||||
|
// Mapeamento de redirecionamento baseado em role
|
||||||
|
const getRoleRedirectPath = (userType: string): string => {
|
||||||
|
switch (userType) {
|
||||||
|
case 'paciente':
|
||||||
|
return '/paciente'
|
||||||
|
case 'profissional':
|
||||||
|
return '/profissional'
|
||||||
|
case 'administrador':
|
||||||
|
return '/dashboard'
|
||||||
|
default:
|
||||||
|
return '/'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const handleLogin = async (e: React.FormEvent) => {
|
const handleLogin = async (e: React.FormEvent) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
@ -23,32 +36,73 @@ export default function LoginPage() {
|
|||||||
setError('')
|
setError('')
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Tentar fazer login usando o contexto com tipo profissional
|
// Tentar fazer login com cada tipo de usuário até conseguir
|
||||||
const success = await login(credentials.email, credentials.password, 'profissional')
|
// Ordem de prioridade: profissional (inclui médico), paciente, administrador
|
||||||
|
const userTypes: Array<'paciente' | 'profissional' | 'administrador'> = [
|
||||||
|
'profissional', // Tentar profissional PRIMEIRO pois inclui médicos
|
||||||
|
'paciente',
|
||||||
|
'administrador'
|
||||||
|
]
|
||||||
|
|
||||||
if (success) {
|
let lastError: AuthenticationError | Error | null = null
|
||||||
console.log('[LOGIN-PROFISSIONAL] Login bem-sucedido, redirecionando...')
|
let loginAttempted = false
|
||||||
|
|
||||||
// Redirecionamento direto - solução que funcionou
|
for (const userType of userTypes) {
|
||||||
window.location.href = '/profissional'
|
try {
|
||||||
|
console.log(`[LOGIN] Tentando login como ${userType}...`)
|
||||||
|
const loginSuccess = await login(credentials.email, credentials.password, userType)
|
||||||
|
|
||||||
|
if (loginSuccess) {
|
||||||
|
loginAttempted = true
|
||||||
|
console.log('[LOGIN] Login bem-sucedido como', userType)
|
||||||
|
console.log('[LOGIN] User state:', user)
|
||||||
|
|
||||||
|
// Aguardar um pouco para o state do usuário ser atualizado
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 500))
|
||||||
|
|
||||||
|
// Obter o userType atualizado do localStorage (que foi salvo pela função login)
|
||||||
|
const storedUser = localStorage.getItem('auth_user')
|
||||||
|
if (storedUser) {
|
||||||
|
try {
|
||||||
|
const userData = JSON.parse(storedUser)
|
||||||
|
const redirectPath = getRoleRedirectPath(userData.userType)
|
||||||
|
console.log('[LOGIN] Redirecionando para:', redirectPath)
|
||||||
|
router.push(redirectPath)
|
||||||
|
} catch (parseErr) {
|
||||||
|
console.error('[LOGIN] Erro ao parsear user do localStorage:', parseErr)
|
||||||
|
router.push('/')
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.warn('[LOGIN] Usuário não encontrado no localStorage')
|
||||||
|
router.push('/')
|
||||||
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('[LOGIN-PROFISSIONAL] Erro no login:', err)
|
lastError = err as AuthenticationError | Error
|
||||||
|
const errorMsg = err instanceof Error ? err.message : String(err)
|
||||||
|
console.log(`[LOGIN] Falha ao tentar como ${userType}:`, errorMsg)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (err instanceof AuthenticationError) {
|
// Se chegou aqui, nenhum tipo funcionou
|
||||||
// Verificar se é erro de credenciais inválidas (pode ser email não confirmado)
|
console.error('[LOGIN] Nenhum tipo de usuário funcionou. Erro final:', lastError)
|
||||||
if (err.code === '400' || err.details?.error_code === 'invalid_credentials') {
|
|
||||||
setError(
|
if (lastError instanceof AuthenticationError) {
|
||||||
'⚠️ Email ou senha incorretos. Se você acabou de se cadastrar, ' +
|
const errorMsg = lastError.message || lastError.details?.error_code || ''
|
||||||
'verifique sua caixa de entrada e clique no link de confirmação ' +
|
if (lastError.code === '400' || errorMsg.includes('invalid_credentials') || errorMsg.includes('Email or password')) {
|
||||||
'que foi enviado para ' + credentials.email
|
setError('❌ Email ou senha incorretos. Verifique suas credenciais.')
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
setError(err.message)
|
setError(lastError.message || 'Erro ao fazer login. Tente novamente.')
|
||||||
}
|
}
|
||||||
|
} else if (lastError instanceof Error) {
|
||||||
|
setError(lastError.message || 'Erro desconhecido ao fazer login.')
|
||||||
} else {
|
} else {
|
||||||
setError('Erro inesperado. Tente novamente.')
|
setError('Falha ao fazer login. Credenciais inválidas ou conta não encontrada.')
|
||||||
}
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error('[LOGIN] Erro no login:', err)
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
@ -61,7 +115,7 @@ export default function LoginPage() {
|
|||||||
<div className="max-w-md w-full space-y-8">
|
<div className="max-w-md w-full space-y-8">
|
||||||
<div className="text-center">
|
<div className="text-center">
|
||||||
<h2 className="mt-6 text-3xl font-extrabold text-foreground">
|
<h2 className="mt-6 text-3xl font-extrabold text-foreground">
|
||||||
Login Profissional de Saúde
|
Entrar
|
||||||
</h2>
|
</h2>
|
||||||
<p className="mt-2 text-sm text-muted-foreground">
|
<p className="mt-2 text-sm text-muted-foreground">
|
||||||
Entre com suas credenciais para acessar o sistema
|
Entre com suas credenciais para acessar o sistema
|
||||||
@ -70,7 +124,7 @@ export default function LoginPage() {
|
|||||||
|
|
||||||
<Card>
|
<Card>
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle className="text-center">Acesso ao Sistema</CardTitle>
|
<CardTitle className="text-center">Login</CardTitle>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
<form onSubmit={handleLogin} className="space-y-6">
|
<form onSubmit={handleLogin} className="space-y-6">
|
||||||
@ -121,9 +175,8 @@ export default function LoginPage() {
|
|||||||
</Button>
|
</Button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
|
||||||
<div className="mt-4 text-center">
|
<div className="mt-4 text-center">
|
||||||
<Button variant="outline" asChild className="w-full hover:bg-primary! hover:text-white! hover:border-primary! transition-all duration-200">
|
<Button variant="ghost" asChild className="w-full">
|
||||||
<Link href="/">
|
<Link href="/">
|
||||||
Voltar ao Início
|
Voltar ao Início
|
||||||
</Link>
|
</Link>
|
||||||
|
|||||||
@ -23,24 +23,7 @@ export function HeroSection() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{}
|
|
||||||
<div className="flex flex-col sm:flex-row gap-4">
|
|
||||||
<Button
|
|
||||||
size="lg"
|
|
||||||
className="bg-primary hover:bg-primary/90 text-primary-foreground cursor-pointer shadow-sm shadow-blue-500/10 border border-blue-200 dark:shadow-none dark:border-transparent"
|
|
||||||
asChild
|
|
||||||
>
|
|
||||||
<Link href="/login-paciente">Portal do Paciente</Link>
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
size="lg"
|
|
||||||
variant="outline"
|
|
||||||
className="text-primary border-primary bg-transparent cursor-pointer shadow-sm shadow-blue-500/10 border border-blue-200 hover:bg-blue-50 dark:shadow-none dark:border-primary dark:hover:bg-primary dark:hover:text-primary-foreground"
|
|
||||||
asChild
|
|
||||||
>
|
|
||||||
<Link href="/login">Sou Profissional de Saúde</Link>
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{}
|
{}
|
||||||
|
|||||||
@ -50,20 +50,8 @@ export function Header() {
|
|||||||
className="text-primary border-primary bg-transparent shadow-sm shadow-blue-500/10 border border-blue-200 hover:bg-blue-50 dark:shadow-none dark:border-primary dark:hover:bg-primary dark:hover:text-primary-foreground"
|
className="text-primary border-primary bg-transparent shadow-sm shadow-blue-500/10 border border-blue-200 hover:bg-blue-50 dark:shadow-none dark:border-primary dark:hover:bg-primary dark:hover:text-primary-foreground"
|
||||||
asChild
|
asChild
|
||||||
>
|
>
|
||||||
|
<Link href="/login">Entrar</Link>
|
||||||
<Link href="/login-paciente">Sou Paciente</Link>
|
|
||||||
</Button>
|
</Button>
|
||||||
<Button className="bg-primary hover:bg-primary/90 text-primary-foreground shadow-sm shadow-blue-500/10 border border-blue-200 dark:shadow-none dark:border-transparent">
|
|
||||||
<Link href="/login">Sou Profissional de Saúde</Link>
|
|
||||||
</Button>
|
|
||||||
<Link href="/login-admin">
|
|
||||||
<Button
|
|
||||||
variant="outline"
|
|
||||||
className="text-primary border-primary bg-transparent shadow-sm shadow-blue-500/10 border border-blue-200 hover:bg-blue-50 dark:shadow-none dark:border-primary dark:hover:bg-primary dark:hover:text-primary-foreground cursor-pointer"
|
|
||||||
>
|
|
||||||
Sou Administrador de uma Clínica
|
|
||||||
</Button>
|
|
||||||
</Link>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{}
|
{}
|
||||||
@ -101,19 +89,8 @@ export function Header() {
|
|||||||
className="text-primary border-primary bg-transparent shadow-sm shadow-blue-500/10 border border-blue-200 hover:bg-blue-50 dark:shadow-none dark:border-primary dark:hover:bg-primary dark:hover:text-primary-foreground"
|
className="text-primary border-primary bg-transparent shadow-sm shadow-blue-500/10 border border-blue-200 hover:bg-blue-50 dark:shadow-none dark:border-primary dark:hover:bg-primary dark:hover:text-primary-foreground"
|
||||||
asChild
|
asChild
|
||||||
>
|
>
|
||||||
<Link href="/login-paciente">Sou Paciente</Link>
|
<Link href="/login">Entrar</Link>
|
||||||
</Button>
|
</Button>
|
||||||
<Button className="bg-primary hover:bg-primary/90 text-primary-foreground w-full shadow-sm shadow-blue-500/10 border border-blue-200 dark:shadow-none dark:border-transparent">
|
|
||||||
<Link href="/login">Sou Profissional de Saúde</Link>
|
|
||||||
</Button>
|
|
||||||
<Link href="/login-admin">
|
|
||||||
<Button
|
|
||||||
variant="outline"
|
|
||||||
className="text-primary border-primary bg-transparent w-full shadow-sm shadow-blue-500/10 border border-blue-200 hover:bg-blue-50 dark:shadow-none dark:border-primary dark:hover:bg-primary dark:hover:text-primary-foreground cursor-pointer"
|
|
||||||
>
|
|
||||||
Sou Administrador de uma Clínica
|
|
||||||
</Button>
|
|
||||||
</Link>
|
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -126,17 +126,6 @@ export default function ProtectedRoute({
|
|||||||
<p className="text-gray-600 mb-4">
|
<p className="text-gray-600 mb-4">
|
||||||
Você não tem permissão para acessar esta página.
|
Você não tem permissão para acessar esta página.
|
||||||
</p>
|
</p>
|
||||||
<p className="text-sm text-gray-500 mb-6">
|
|
||||||
Tipo de acesso necessário: {requiredUserType.join(' ou ')}
|
|
||||||
<br />
|
|
||||||
Seu tipo de acesso: {user.userType}
|
|
||||||
</p>
|
|
||||||
<button
|
|
||||||
onClick={() => router.push(USER_TYPE_ROUTES[user.userType])}
|
|
||||||
className="px-4 py-2 bg-blue-600 text-white rounded hover:bg-blue-700 cursor-pointer"
|
|
||||||
>
|
|
||||||
Ir para minha área
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|||||||
@ -298,8 +298,9 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
|||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const errorMessage = error instanceof Error ? error.message : String(error)
|
||||||
throw new AuthenticationError(
|
throw new AuthenticationError(
|
||||||
'Erro inesperado durante o login',
|
errorMessage || 'Erro inesperado durante o login',
|
||||||
'UNKNOWN_ERROR',
|
'UNKNOWN_ERROR',
|
||||||
error
|
error
|
||||||
)
|
)
|
||||||
|
|||||||
@ -189,15 +189,7 @@ class HttpClient {
|
|||||||
|
|
||||||
// Redirecionar para login
|
// Redirecionar para login
|
||||||
if (typeof window !== 'undefined') {
|
if (typeof window !== 'undefined') {
|
||||||
const userType = localStorage.getItem(AUTH_STORAGE_KEYS.USER_TYPE) || 'profissional'
|
window.location.href = '/login'
|
||||||
const loginRoutes = {
|
|
||||||
profissional: '/login',
|
|
||||||
paciente: '/login-paciente',
|
|
||||||
administrador: '/login-admin'
|
|
||||||
}
|
|
||||||
|
|
||||||
const loginRoute = loginRoutes[userType as keyof typeof loginRoutes] || '/login'
|
|
||||||
window.location.href = loginRoute
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -85,6 +85,6 @@ export const USER_TYPE_ROUTES: UserTypeRoutes = {
|
|||||||
|
|
||||||
export const LOGIN_ROUTES: LoginRoutes = {
|
export const LOGIN_ROUTES: LoginRoutes = {
|
||||||
profissional: '/login',
|
profissional: '/login',
|
||||||
paciente: '/login-paciente',
|
paciente: '/login',
|
||||||
administrador: '/login-admin',
|
administrador: '/login',
|
||||||
} as const
|
} as const
|
||||||
Loading…
x
Reference in New Issue
Block a user