RicharDVD
RicharDVD
NNuxt
Created by RicharDVD on 9/16/2024 in #❓・help
Pinia state leaks across browser sessions
Thank you for pointing it out. Fixed it😃
54 replies
NNuxt
Created by RicharDVD on 9/16/2024 in #❓・help
Pinia state leaks across browser sessions
I did confirm that this was indeed the issue😃 Thank you so much!
54 replies
NNuxt
Created by RicharDVD on 9/16/2024 in #❓・help
Pinia state leaks across browser sessions
1 last thing, I have ISR set to 3600 (so 1 hour). Just for my understanding, under what circumstances will the state be leaked since it's hard for me to reproduce?
54 replies
NNuxt
Created by RicharDVD on 9/16/2024 in #❓・help
Pinia state leaks across browser sessions
Thank you guys for helping out. I think I will indeed go with this route since it's an easy solution in my case
54 replies
NNuxt
Created by RicharDVD on 9/16/2024 in #❓・help
Pinia state leaks across browser sessions
I think you might be right. But let's say I make the navbar client only (which uses some auth logic) it would jump into the page which is not so nice. I think I'd have to just remove the cache rules and see if that works out.
54 replies
NNuxt
Created by RicharDVD on 9/16/2024 in #❓・help
Pinia state leaks across browser sessions
I do use isr on some routes
54 replies
NNuxt
Created by RicharDVD on 9/16/2024 in #❓・help
Pinia state leaks across browser sessions
That is what makes it so hard
54 replies
NNuxt
Created by RicharDVD on 9/16/2024 in #❓・help
Pinia state leaks across browser sessions
The thing is, the same for me😅 It happens only occasionally
54 replies
NNuxt
Created by RicharDVD on 9/16/2024 in #❓・help
Pinia state leaks across browser sessions
If you look in their docs, they now say that the npm package is "pinia-plugin-persistedstate". https://prazdevs.github.io/pinia-plugin-persistedstate/frameworks/nuxt.html
54 replies
NNuxt
Created by RicharDVD on 9/16/2024 in #❓・help
Pinia state leaks across browser sessions
That is because they moved the module
54 replies
NNuxt
Created by RicharDVD on 9/16/2024 in #❓・help
Pinia state leaks across browser sessions
I think that is because you are using an older version of the module. Since 4.0.0 it has updated to piniaPluginPersistedstate (https://github.com/prazdevs/pinia-plugin-persistedstate/releases/tag/v4.0.0)
54 replies
NNuxt
Created by RicharDVD on 9/16/2024 in #❓・help
Pinia state leaks across browser sessions
Only thing I could think of was the fact that I access useAuthStore within the onRequest and onResponseError callback. That that might be the reason but not sure
54 replies
NNuxt
Created by RicharDVD on 9/16/2024 in #❓・help
Pinia state leaks across browser sessions
I do indeed use the nuxt module. It is very hard to reproduce since it happens only happens occasionally. For now, I decided to just use a custom composable where the state is stored with
useCookie()
useCookie()
instead of a pinia store. See if we will run into it again. If so, it must be something completely different.
54 replies
NNuxt
Created by Spctr on 10/15/2024 in #❓・help
Frontend middleware auth with backend auth
Happy to help😃
12 replies
NNuxt
Created by Spctr on 10/15/2024 in #❓・help
Frontend middleware auth with backend auth
For the plugin you can just rename the file to [filename].client.ts and for the middleware:
export default defineNuxtRouteMiddleware(() => {
if (import.meta.server) {
return;
}

...
}
export default defineNuxtRouteMiddleware(() => {
if (import.meta.server) {
return;
}

...
}
12 replies
NNuxt
Created by Spctr on 10/15/2024 in #❓・help
Frontend middleware auth with backend auth
I believe your solution would only work client side. I would make the plugin a client only plugin and the route middleware only run on the client (by checking import.meta.server and early returning). See if that helps you any further
12 replies
NNuxt
Created by RicharDVD on 9/16/2024 in #❓・help
Pinia state leaks across browser sessions
@Dovendyret The store looks as follows:
import { defineStore } from 'pinia';
import type { UserProfile } from '~/utils/types';

export const useAuthStore = defineStore(
'auth',
() => {
const accessToken = ref('');
const refreshToken = ref('');
const profile = ref<UserProfile | null>(null);

const isLoggedIn = computed(() => !!accessToken.value);

function signIn(login: LoginResponse) {
accessToken.value = login.access_token;
refreshToken.value = login.refresh_token;
profile.value = login.user;
}

function logout() {
accessToken.value = '';
refreshToken.value = '';
profile.value = null;
}

return {
accessToken,
refreshToken,
profile,
logout,
isLoggedIn,
signIn,
};
},
{
persist: {
storage: piniaPluginPersistedstate.cookies(),
},
},
);
import { defineStore } from 'pinia';
import type { UserProfile } from '~/utils/types';

export const useAuthStore = defineStore(
'auth',
() => {
const accessToken = ref('');
const refreshToken = ref('');
const profile = ref<UserProfile | null>(null);

const isLoggedIn = computed(() => !!accessToken.value);

function signIn(login: LoginResponse) {
accessToken.value = login.access_token;
refreshToken.value = login.refresh_token;
profile.value = login.user;
}

function logout() {
accessToken.value = '';
refreshToken.value = '';
profile.value = null;
}

return {
accessToken,
refreshToken,
profile,
logout,
isLoggedIn,
signIn,
};
},
{
persist: {
storage: piniaPluginPersistedstate.cookies(),
},
},
);
This is where the default state is set.
54 replies
NNuxt
Created by RicharDVD on 9/16/2024 in #❓・help
Pinia state leaks across browser sessions
We unfortunately encountered the same issue so this didn't seem to be the fix. Do you maybe have any other idea's that could cause this? It's very hard to reproduce this since it only happens once in a while and I am not sure what circumstances cause this to happen.
54 replies
NNuxt
Created by hz2222 on 9/27/2024 in #❓・help
sending notifications in Nuxt
In that case you could look at something like https://onesignal.com/
10 replies
NNuxt
Created by hz2222 on 9/27/2024 in #❓・help
sending notifications in Nuxt
It also has an example on the homepage of how you would use it using Nuxt
10 replies