Admin platform, with users, transactions, games and admin creation
This commit is contained in:
@@ -11,6 +11,8 @@ import TestGameBoard from '@/pages/TestGameBoard.vue'
|
||||
import SinglePlayerGamePage from '@/pages/game/SinglePlayerGamePage.vue'
|
||||
import RegisterPage from '@/pages/register/RegisterPage.vue'
|
||||
import CoinsPurchasePage from '@/pages/purchase/CoinPurchasePage.vue'
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
import AdminPage from '@/pages/admin/AdminPage.vue'
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(import.meta.env.BASE_URL),
|
||||
@@ -19,6 +21,7 @@ const router = createRouter({
|
||||
path: '/',
|
||||
name: 'home',
|
||||
component: HomePage,
|
||||
meta: { requiresAdmin: false }
|
||||
},
|
||||
{
|
||||
path: '/login',
|
||||
@@ -35,7 +38,7 @@ const router = createRouter({
|
||||
name: 'bisca3',
|
||||
component: SinglePlayerGamePage,
|
||||
props: { gameType: 3 },
|
||||
meta: { requiresAuth: true },
|
||||
meta: { requiresAuth: true, requiresAdmin: false },
|
||||
},
|
||||
{
|
||||
path: '/game/9',
|
||||
@@ -54,6 +57,12 @@ const router = createRouter({
|
||||
component: CoinsPurchasePage,
|
||||
meta: { requiresAuth: true },
|
||||
},
|
||||
{
|
||||
path: '/admin',
|
||||
name: 'admin',
|
||||
component: AdminPage,
|
||||
meta: { requiresAuth: true, requiresAdmin: true },
|
||||
},
|
||||
{
|
||||
path: '/testing',
|
||||
children: [
|
||||
@@ -88,6 +97,7 @@ const router = createRouter({
|
||||
|
||||
router.beforeEach((to, from, next) => {
|
||||
const requiresAuth = to.matched.some((record) => record.meta.requiresAuth)
|
||||
const requiresAdmin = to.matched.some((record) => record.meta.requiresAdmin)
|
||||
|
||||
if (requiresAuth) {
|
||||
const token = localStorage.getItem('token')
|
||||
@@ -96,6 +106,10 @@ router.beforeEach((to, from, next) => {
|
||||
return next({ name: 'login' })
|
||||
}
|
||||
}
|
||||
|
||||
if (useAuthStore().isAdmin && to.name === 'home') return next({ name: 'admin' })
|
||||
if (requiresAdmin && !useAuthStore().isAdmin) return next({ name: 'home' })
|
||||
|
||||
next()
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user