91 lines
2.2 KiB
JavaScript
91 lines
2.2 KiB
JavaScript
import HomePage from '@/pages/home/HomePage.vue'
|
|
import LoginPage from '@/pages/login/LoginPage.vue'
|
|
import LaravelPage from '@/pages/testing/LaravelPage.vue'
|
|
import WebsocketsPage from '@/pages/testing/WebsocketsPage.vue'
|
|
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 UserPage from '@/pages/user/UserPage.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),
|
|
routes: [
|
|
{
|
|
path: '/',
|
|
component: HomePage,
|
|
},
|
|
{
|
|
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: '/user',
|
|
component: UserPage,
|
|
},
|
|
{
|
|
path: '/testing',
|
|
children: [
|
|
{
|
|
path: 'laravel',
|
|
component: LaravelPage,
|
|
},
|
|
{
|
|
path: 'websockets',
|
|
component: WebsocketsPage,
|
|
},
|
|
{
|
|
path: 'animations',
|
|
component: TestAnimations,
|
|
},
|
|
{
|
|
path: 'dealing',
|
|
component: TestDealing,
|
|
},
|
|
{
|
|
path: 'all-animations',
|
|
component: TestAllAnimations,
|
|
},
|
|
{
|
|
path: 'gameboard',
|
|
component: TestGameBoard,
|
|
},
|
|
],
|
|
},
|
|
],
|
|
})
|
|
|
|
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
|