Repository navigation
Occassional data leak across requests with SSR #2803
Replies: 2 comments
|
This is a classic SSR cross-request state pollution bug. In your Nuxt plugin, you're creating a The root cause is usually one of:
Fix: Make sure you access the store inside each request, not at plugin initialization: export default defineNuxtPlugin((nuxtApp) => {
const api = $fetch.create({
async onRequest({ options }) {
// Get fresh store state per request
const sessionStore = useSessionStore(nuxtApp.$pinia);
const token = sessionStore.token;
if (token) {
options.headers = {
...options.headers,
Authorization: `Bearer ${token}`,
};
}
},
});
return { provide: { api } };
});Also ensure:
This is a critical security issue — I'd prioritize fixing it. The pattern is almost always "store accessed at module scope or plugin init instead of per-request". |
Uh oh!
There was an error while loading. Please reload this page.
Every once in a while, all of a sudden all users are logged in as the same user. I suspect it has to do with our usage of the pinia store within our nuxt plugin. The plugin code looks as follows:
Am I doing something wrong here? I can't really reproduce it since it only happens once in a while.
For fuller context I use this composable as a useFetch wrapper:
And this is the auth store:
All reactions