login redirecionando pra home e acessando home se tiver logado

This commit is contained in:
2026-05-03 13:03:14 -05:00
parent 404e2d457b
commit b8dbb5869d
4 changed files with 34 additions and 6 deletions

View File

@@ -94,18 +94,27 @@
isLoading.value = true
try {
const res = await fetch('/auth/login', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ email, password }),
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ email, password }),
})
const data = await res.json()
if (!res.ok) {
const data = await res.json().catch(() => ({}))
$toast.error(data.message ?? 'Erro para efetuar o login. Tente novamente.')
return
const data = await res.json().catch(() => ({}))
$toast.error(data.message ?? 'Erro para efetuar o login. Tente novamente.')
return
}
const token = useCookie('token')
if(data) token.value = data.access_token
$toast.success('Login realizado com sucesso!')
await navigateTo('/home')
} catch {
$toast.error('Erro para efetuar o login. Tente novamente.')
} finally {