elearning/frontend_management/middleware/admin.ts

18 lines
No EOL
391 B
TypeScript

export default defineNuxtRouteMiddleware((to, from) => {
// Skip on server side - let client handle auth
if (process.server) {
return;
}
const authStore = useAuthStore();
// Restore session if not authenticated
if (!authStore.isAuthenticated) {
authStore.checkAuth();
}
// Check if user is admin
if (!authStore.isAdmin) {
return navigateTo('/login');
}
});