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;
|
|
|
|
|
}
|
|
|
|
|
|
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 if user is admin
|
2026-01-12 16:49:58 +07:00
|
|
|
if (!authStore.isAdmin) {
|
|
|
|
|
return navigateTo('/login');
|
|
|
|
|
}
|
|
|
|
|
});
|