Fetch session in authenticated middleware
All checks were successful
/ build (push) Successful in 1m19s
/ deploy (push) Successful in 16s

The authenticated middleware runs before the page content is rendered.
This means that it'll run before the session is fetched in app.vue on
pages that are protected by it on the first load.  Fetch the session in
the middleware so that it doesn't act before the session is initalized.
This commit is contained in:
Hornwitser 2025-05-26 13:55:01 +02:00
parent cf90de1aae
commit e8ff87d507

View file

@ -1,6 +1,11 @@
export default defineNuxtRouteMiddleware(async (to, from) => {
const accountStore = useAccountStore();
const event = useRequestEvent();
const sessionStore = useSessionStore();
await callOnce("fetch-session", async () => {
await sessionStore.fetch(event);
})
const accountStore = useAccountStore();
if (!accountStore.valid) {
console.log("Not logged in, redirecting to /login");
return navigateTo("/login");