2025-08-07 14:58:08 +02:00
|
|
|
export default defineNuxtRouteMiddleware(async (to) => {
|
2025-08-06 14:31:16 +02:00
|
|
|
// Skip auth for public pages
|
|
|
|
|
if (to.meta.auth === false) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-07 14:58:08 +02:00
|
|
|
// Use the same auth system as the rest of the app
|
|
|
|
|
const { isAuthenticated, checkAuth, user } = useAuth();
|
|
|
|
|
|
2025-08-07 17:01:01 +02:00
|
|
|
// Ensure auth is checked if user isn't loaded - use forced check for middleware
|
2025-08-07 14:58:08 +02:00
|
|
|
if (!user.value) {
|
2025-08-07 17:01:01 +02:00
|
|
|
await checkAuth(true); // Force check to bypass throttling in middleware
|
2025-08-07 14:58:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!isAuthenticated.value) {
|
2025-08-06 14:31:16 +02:00
|
|
|
return navigateTo('/login');
|
|
|
|
|
}
|
|
|
|
|
});
|