fix: added missing route

This commit is contained in:
2025-12-29 14:47:32 +00:00
parent 0ecdc30bd4
commit 4b311c74eb
+12 -26
View File
@@ -6,41 +6,21 @@ import TestAnimations from '@/pages/TestAnimations.vue'
import TestDealing from '@/pages/TestDealing.vue' import TestDealing from '@/pages/TestDealing.vue'
import TestAllAnimations from '@/pages/TestAllAnimations.vue' import TestAllAnimations from '@/pages/TestAllAnimations.vue'
import TestGameBoard from '@/pages/TestGameBoard.vue' import TestGameBoard from '@/pages/TestGameBoard.vue'
import UserPage from '@/pages/user/UserPage.vue'
import SinglePlayerGamePage from '@/pages/game/SinglePlayerGamePage.vue' import SinglePlayerGamePage from '@/pages/game/SinglePlayerGamePage.vue'
import { createRouter, createWebHistory } from 'vue-router' import { createRouter, createWebHistory } from 'vue-router'
import { toast } from 'vue-sonner' import { toast } from 'vue-sonner'
import TestAnimations from '@/pages/TestAnimations.vue'
import TestDealing from '@/pages/TestDealing.vue'
import TestAllAnimations from '@/pages/TestAllAnimations.vue'
import TestGameBoard from '@/pages/TestGameBoard.vue'
import SinglePlayerGamePage from '@/pages/game/SinglePlayerGamePage.vue'
const router = createRouter({ const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL), history: createWebHistory(import.meta.env.BASE_URL),
routes: [ routes: [
{ {
path: '/', path: '/',
name: 'home',
component: HomePage, component: HomePage,
}, },
{ {
path: '/login', path: '/login',
name: 'login',
component: LoginPage, component: LoginPage,
},
{
path: '/game/3',
name: 'bisca3',
component: SinglePlayerGamePage,
props: { gameType: 3 },
meta: { requiresAuth: true },
},
{
path: '/game/9',
name: 'bisca9',
component: SinglePlayerGamePage,
props: { gameType: 9 },
meta: { requiresAuth: true },
}, },
{ {
path: '/game/3', path: '/game/3',
@@ -56,6 +36,10 @@ const router = createRouter({
props: { gameType: 9 }, props: { gameType: 9 },
meta: { requiresAuth: true }, meta: { requiresAuth: true },
}, },
{
path: '/user',
component: UserPage,
},
{ {
path: '/testing', path: '/testing',
children: [ children: [
@@ -89,13 +73,15 @@ const router = createRouter({
}) })
router.beforeEach((to, from, next) => { router.beforeEach((to, from, next) => {
const requiresAuth = to.matched.some((record) => record.meta.requiresAuth) if (to.meta.requiresAuth) {
const token = localStorage.getItem('token') // Ou useAuthStore().token
if (requiresAuth) {
const token = localStorage.getItem('token')
if (!token) { if (!token) {
return next({ name: 'login' }) toast.error('Acesso Negado', {
description: 'Precisas de fazer login para aceder ao jogo.',
duration: 4000,
})
return next({ name: 'home' })
} }
} }
next() next()