mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-07 19:10:12 +08:00
update app
This commit is contained in:
1 parent
d924ccaaa9
commit
4ddbb5aede
7 files changed
+2
-2
No files matched your search
@@ -0,0 +1,79 @@
|
||||
import { createRouter, createWebHistory } from 'vue-router'
|
||||
import GamePage from './views/GamePage.vue'
|
||||
import LoginPage from './views/LoginPage.vue'
|
||||
import RegisterPage from './views/RegisterPage.vue'
|
||||
import ChooseUsernamePage from './views/ChooseUsernamePage.vue'
|
||||
import QuestMapPage from './views/QuestMapPage.vue'
|
||||
import LeaderboardPage from './views/LeaderboardPage.vue'
|
||||
import LandingPage from './views/LandingPage.vue'
|
||||
import { isLoggedIn } from './utils/auth'
|
||||
|
||||
const routes = [
|
||||
{
|
||||
path: '/',
|
||||
name: 'landing-page',
|
||||
component: LandingPage,
|
||||
},
|
||||
{
|
||||
path: '/login',
|
||||
name: 'login',
|
||||
component: LoginPage,
|
||||
meta: { requiresGuest: true },
|
||||
},
|
||||
{
|
||||
path: '/register',
|
||||
name: 'register',
|
||||
component: RegisterPage,
|
||||
meta: { requiresGuest: true },
|
||||
},
|
||||
{
|
||||
path: '/game/:questId',
|
||||
name: 'game',
|
||||
component: GamePage,
|
||||
props: true,
|
||||
meta: { requiresAuth: true },
|
||||
},
|
||||
{
|
||||
path: '/choose-username',
|
||||
name: 'choose-username',
|
||||
component: ChooseUsernamePage,
|
||||
meta: { requiresGuest: true },
|
||||
},
|
||||
{
|
||||
path: '/map',
|
||||
name: 'map',
|
||||
component: QuestMapPage,
|
||||
meta: { requiresAuth: true },
|
||||
},
|
||||
{
|
||||
path: '/leaderboard',
|
||||
name: 'leaderboard',
|
||||
component: LeaderboardPage,
|
||||
},
|
||||
]
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(),
|
||||
routes,
|
||||
})
|
||||
|
||||
router.beforeEach(async (to, _from, next) => {
|
||||
const loggedIn = await isLoggedIn()
|
||||
// Check if the route requires authentication
|
||||
if (to.meta.requiresAuth && !loggedIn) {
|
||||
// Check if the user isn't authenticated
|
||||
// Redirect to the login page
|
||||
next({
|
||||
name: 'register',
|
||||
query: { redirect: to.fullPath }, // Optionally pass a redirect parameter
|
||||
})
|
||||
} else if (to.meta.requiresGuest && loggedIn) {
|
||||
next({
|
||||
name: 'map',
|
||||
})
|
||||
} else {
|
||||
next()
|
||||
}
|
||||
})
|
||||
|
||||
export default router
|
||||
Reference in new issue
Block a user