mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-08 03:20:12 +08:00
feat: update frontend to use cookie session
* use SessionMiddleware in socket.io server * add back jwtStrategy for commands
This commit is contained in:
1 parent
be5cd152a9
commit
34c277c886
13 files changed
+90
-116
No files matched your search
+23
-20
@@ -1,11 +1,14 @@
|
||||
import { createRouter, createWebHistory } from 'vue-router'
|
||||
import GamePage from './views/GamePage.vue'
|
||||
import AuthPage from './views/AuthPage.vue'
|
||||
import { isAuthenticated } from './utils/auth'
|
||||
|
||||
const routes = [
|
||||
{
|
||||
path: '/',
|
||||
redirect: '/game',
|
||||
},
|
||||
{
|
||||
path: '/login',
|
||||
name: 'auth',
|
||||
component: AuthPage,
|
||||
meta: { requiresGuest: true },
|
||||
@@ -23,24 +26,24 @@ const router = createRouter({
|
||||
routes,
|
||||
})
|
||||
|
||||
router.beforeEach((to, from, next) => {
|
||||
console.log(to, from)
|
||||
const isAuthed = isAuthenticated.value
|
||||
// Check if the route requires authentication
|
||||
if (to.meta.requiresAuth && !isAuthed) {
|
||||
// Check if the user isn't authenticated
|
||||
// Redirect to the login page
|
||||
next({
|
||||
name: 'auth',
|
||||
query: { redirect: to.fullPath }, // Optionally pass a redirect parameter
|
||||
})
|
||||
} else if (to.meta.requiresGuest && isAuthed) {
|
||||
next({
|
||||
name: 'game', // Or any default authenticated user route
|
||||
})
|
||||
} else {
|
||||
next() // Always call next() at the end
|
||||
}
|
||||
})
|
||||
// router.beforeEach((to, from, next) => {
|
||||
// console.log(to, from)
|
||||
// const isAuthed = isAuthenticated.value
|
||||
// // Check if the route requires authentication
|
||||
// if (to.meta.requiresAuth && !isAuthed) {
|
||||
// // Check if the user isn't authenticated
|
||||
// // Redirect to the login page
|
||||
// next({
|
||||
// name: 'auth',
|
||||
// query: { redirect: to.fullPath }, // Optionally pass a redirect parameter
|
||||
// })
|
||||
// } else if (to.meta.requiresGuest && isAuthed) {
|
||||
// next({
|
||||
// name: 'game', // Or any default authenticated user route
|
||||
// })
|
||||
// } else {
|
||||
// next() // Always call next() at the end
|
||||
// }
|
||||
// })
|
||||
|
||||
export default router
|
||||
Reference in new issue
Block a user