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.
8 lines
233 B
TypeScript
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");
|
|
}
|
|
})
|