login redirecionando pra home e acessando home se tiver logado
This commit is contained in:
@@ -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