19 lines
511 B
TypeScript
19 lines
511 B
TypeScript
export default defineNuxtRouteMiddleware(async (to) => {
|
|
// Skip auth for public pages
|
|
if (to.meta.auth === false) {
|
|
return;
|
|
}
|
|
|
|
// Use the same auth system as the rest of the app
|
|
const { isAuthenticated, checkAuth, user } = useAuth();
|
|
|
|
// Ensure auth is checked if user isn't loaded - use forced check for middleware
|
|
if (!user.value) {
|
|
await checkAuth(true); // Force check to bypass throttling in middleware
|
|
}
|
|
|
|
if (!isAuthenticated.value) {
|
|
return navigateTo('/login');
|
|
}
|
|
});
|