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

@@ -107,6 +107,7 @@ async function criarConta({ email, password }) {
}
$toast.success('Conta criada com sucesso!')
await navigateTo('/login')
} catch {
$toast.error('Erro ao criar conta. Tente novamente.')
} finally {

View File

@@ -0,0 +1,11 @@
<template>
<div>
<h1>OOOIII SOU A HOMEEE</h1>
</div>
</template>
<script setup>
definePageMeta({
middleware: 'auth'
})
</script>

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 {