SyntaxSquad/DADProject#14 added protection to logout inside a game and going to another page
This commit is contained in:
@@ -15,10 +15,12 @@ const router = createRouter({
|
||||
routes: [
|
||||
{
|
||||
path: '/',
|
||||
name: 'home',
|
||||
component: HomePage,
|
||||
},
|
||||
{
|
||||
path: '/login',
|
||||
name: 'login',
|
||||
component: LoginPage,
|
||||
},
|
||||
{
|
||||
@@ -68,15 +70,13 @@ const router = createRouter({
|
||||
})
|
||||
|
||||
router.beforeEach((to, from, next) => {
|
||||
if (to.meta.requiresAuth) {
|
||||
const token = localStorage.getItem('token') // Ou useAuthStore().token
|
||||
const requiresAuth = to.matched.some((record) => record.meta.requiresAuth)
|
||||
|
||||
if (requiresAuth) {
|
||||
const token = localStorage.getItem('token')
|
||||
|
||||
if (!token) {
|
||||
toast.error('Acesso Negado', {
|
||||
description: 'Precisas de fazer login para aceder ao jogo.',
|
||||
duration: 4000,
|
||||
})
|
||||
return next({ name: 'home' })
|
||||
return next({ name: 'login' })
|
||||
}
|
||||
}
|
||||
next()
|
||||
|
||||
Reference in New Issue
Block a user