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:
@@ -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),
|
||||
@@ -19,6 +21,20 @@ const router = createRouter({
|
||||
path: '/login',
|
||||
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: '/testing',
|
||||
children: [
|
||||
@@ -51,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
|
||||
|
||||
Reference in New Issue
Block a user