2026-01-12 16:49:58 +07:00
|
|
|
export default defineNuxtRouteMiddleware((to, from) => {
|
2026-01-16 16:37:16 +07:00
|
|
|
// Skip on server side - let client handle auth
|
|
|
|
|
if (process.server) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Skip middleware on login page
|
|
|
|
|
if (to.path === '/login') {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-12 16:49:58 +07:00
|
|
|
const authStore = useAuthStore();
|
2026-01-16 16:37:16 +07:00
|
|
|
|
|
|
|
|
// Restore session if not authenticated
|
|
|
|
|
if (!authStore.isAuthenticated) {
|
|
|
|
|
authStore.checkAuth();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check authentication after restore
|
2026-01-12 16:49:58 +07:00
|
|
|
if (!authStore.isAuthenticated) {
|
|
|
|
|
return navigateTo('/login');
|
|
|
|
|
}
|
|
|
|
|
});
|