From e8ff87d507127af508a2ca263940749ffff350b6 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Mon, 26 May 2025 13:55:01 +0200 Subject: [PATCH] Fetch session in authenticated middleware 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. --- middleware/authenticated.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/middleware/authenticated.ts b/middleware/authenticated.ts index 7acad5d..3e324c3 100644 --- a/middleware/authenticated.ts +++ b/middleware/authenticated.ts @@ -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");