This commit is contained in:
2026-09-18 14:36:32 +03:00
parent e86085c2f0
commit 5c0963bc51
57 changed files with 1946 additions and 684 deletions
+38 -7
View File
@@ -1,11 +1,14 @@
import { createRouter, createWebHistory } from 'vue-router'
import LoginView from '@/views/LoginView.vue'
import ProfileView from '@/views/ProfileView.vue'
import ProfileView from '@/views/users/ProfileView.vue'
import { issuesRoutes } from '@/router/issues.ts'
import { reportsRoutes } from '@/router/reports.ts'
import { summaryRoutes } from '@/router/summary.ts'
import RegisterView from '@/views/RegisterView.vue'
import HomeView from '@/views/HomeView.vue'
import VerifyEmailView from '@/views/users/VerifyEmailView.vue'
import SignUpView from '@/views/users/SignUpView.vue'
import SignInView from '@/views/users/SignInView.vue'
import { authClient } from '@/lib/auth-client.ts'
import { gamesRoutes } from '@/router/games.ts'
declare module 'vue-router' {
interface RouteMeta {
@@ -22,21 +25,49 @@ const router = createRouter({
meta: { layout: 'Default' },
},
{
path: '/login',
component: LoginView,
name: 'sign-in',
path: '/sign-in',
component: SignInView,
},
{
path: '/register',
component: RegisterView,
path: '/sign-up',
component: SignUpView,
},
{
path: '/verify-email',
component: VerifyEmailView,
},
{
path: '/profile',
component: ProfileView,
meta: { requiresAuth: true },
},
issuesRoutes,
summaryRoutes,
reportsRoutes,
gamesRoutes,
],
})
router.beforeEach(async (to, from) => {
// 1. Fetch the current session from Better Auth
const { data: session } = await authClient.getSession()
// console.log('before each ', { session })
// const session = 'true'
const isAuthenticated = !!session
// 2. If the route requires auth and user is missing, redirect to login
if (to.meta.requiresAuth && !isAuthenticated) {
return { name: 'sign-in', query: { redirect: to.fullPath } }
}
// 3. If route requires a guest (like Login page) and user is logged in, redirect to dashboard
if (to.meta.requiresGuest && isAuthenticated) {
return { name: 'dashboard' }
}
// Implicitly returns undefined / true to allow navigation if conditions don't match
})
export default router