owltide/middleware/authenticated.ts
Hornwitser 264c97b586 Fix server redirectng to login when logged in
When rendering on the server the session is not eagerly loaded when the
authenticated middleware runs, causing it to think the user is not
logged in.  Fix by awaiting the session composable.
2025-03-09 15:51:00 +01:00

8 lines
233 B
TypeScript

export default defineNuxtRouteMiddleware(async (to, from) => {
const { data: session } = await useAccountSession();
if (!session.value) {
console.log("Not logged in, redirecting to /login");
return navigateTo("/login");
}
})