Added game start for single player, 3 and 9 card game types and protected the pages for only logged in players

This commit is contained in:
2025-12-29 11:15:20 +00:00
committed by FernandoJVideira
parent cfda949ea6
commit e68f1357cc
6 changed files with 285 additions and 114 deletions
+29 -2
View File
@@ -6,7 +6,9 @@ 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'
import { createRouter, createWebHistory } from 'vue-router'
import { toast } from 'vue-sonner'
const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
@@ -20,8 +22,18 @@ const router = createRouter({
component: LoginPage,
},
{
path: '/user',
component: UserPage,
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: '/testing',
@@ -55,4 +67,19 @@ const router = createRouter({
],
})
router.beforeEach((to, from, next) => {
if (to.meta.requiresAuth) {
const token = localStorage.getItem('token') // Ou useAuthStore().token
if (!token) {
toast.error('Acesso Negado', {
description: 'Precisas de fazer login para aceder ao jogo.',
duration: 4000,
})
return next({ name: 'home' })
}
}
next()
})
export default router