feat: update frontend to use cookie session

* use SessionMiddleware in socket.io server
* add back jwtStrategy for commands
This commit is contained in:
wancat committed 2023-09-17 12:14:30 +08:00
1 parent be5cd152a9
commit 34c277c886
13 files changed
+90 -116

No files matched your search

+23 -20
View File
@@ -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