23 lines
No EOL
493 B
TypeScript
23 lines
No EOL
493 B
TypeScript
export default defineNuxtRouteMiddleware((to, from) => {
|
|
// Skip on server side - let client handle auth
|
|
if (process.server) {
|
|
return;
|
|
}
|
|
|
|
// Skip middleware on login page
|
|
if (to.path === '/login') {
|
|
return;
|
|
}
|
|
|
|
const authStore = useAuthStore();
|
|
|
|
// Restore session if not authenticated
|
|
if (!authStore.isAuthenticated) {
|
|
authStore.checkAuth();
|
|
}
|
|
|
|
// Check authentication after restore
|
|
if (!authStore.isAuthenticated) {
|
|
return navigateTo('/login');
|
|
}
|
|
}); |