SyntaxSquad/DADProject#14 added protection to logout inside a game and going to another page

This commit is contained in:
2025-12-23 19:43:57 +00:00
parent e54ec58f0c
commit 8505d207e6
6 changed files with 226 additions and 31 deletions
+7 -7
View File
@@ -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()