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:12:05 +02:00
|
|
|
// Ensure auth is checked if user isn't loaded
|
2025-08-07 14:58:08 +02:00
|
|
|
if (!user.value) {
|
2025-08-07 17:12:05 +02:00
|
|
|
await checkAuth();
|
2025-08-07 14:58:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!isAuthenticated.value) {
|
2025-08-06 14:31:16 +02:00
|
|
|
return navigateTo('/login');
|
|
|
|
|
}
|
|
|
|
|
});
|