elearning/frontend_management/middleware/admin.ts

18 lines
391 B
TypeScript
Raw Normal View History

2026-01-12 16:49:58 +07:00
export default defineNuxtRouteMiddleware((to, from) => {
// Skip on server side - let client handle auth
if (process.server) {
return;
}
2026-01-12 16:49:58 +07:00
const authStore = useAuthStore();
// 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');
}
});