diff --git a/src/app.ts b/src/app.ts index 026f288..2525c16 100644 --- a/src/app.ts +++ b/src/app.ts @@ -111,15 +111,19 @@ export async function createAppInstance() { // Install all enabled modules await pluginManager.installAll() - // Set up auth guard + // Set up auth guard router.beforeEach(async (to, _from, next) => { - const authService = container.inject(SERVICE_TOKENS.AUTH_SERVICE) as any + // Import the auth composable to ensure we're using the same instance as the rest of the app + const { auth } = await import('@/composables/useAuth') - if (to.meta.requiresAuth && authService && !authService.isAuthenticated?.value) { + if (to.meta.requiresAuth && !auth.isAuthenticated.value) { + console.log('Auth guard: User not authenticated, redirecting to login') next('/login') - } else if (to.path === '/login' && authService && authService.isAuthenticated?.value) { + } else if (to.path === '/login' && auth.isAuthenticated.value) { + console.log('Auth guard: User already authenticated, redirecting to home') next('/') } else { + console.log(`Auth guard: Allowing navigation to ${to.path}`) next() } })