login redirecionando pra home e acessando home se tiver logado
This commit is contained in:
@@ -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 {
|
||||
|
||||
11
app/pages/(auth)/home/index.vue
Normal file
11
app/pages/(auth)/home/index.vue
Normal file
@@ -0,0 +1,11 @@
|
||||
<template>
|
||||
<div>
|
||||
<h1>OOOIII SOU A HOMEEE</h1>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
definePageMeta({
|
||||
middleware: 'auth'
|
||||
})
|
||||
</script>
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user