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.
This commit is contained in:
parent
cf90de1aae
commit
e8ff87d507
1 changed files with 6 additions and 1 deletions
|
@ -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");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue