You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm not 100% if the issue if the issue is on my end or not (and i'm having hard time to figuring it)
I can successfully log in with the module but me (and my users are randomly logged out)
It was working fine until a couple of week and i'm not able to identify the source of the issue and the pattern that triggers this
in my /server/plugin/session.ts
exportdefaultdefineNitroPlugin(async(nitroApp)=>{console.log('session plugin',{ sessionHooks });sessionHooks.hook('fetch',async(session,event)=>{try{console.log('1. Getting user session',{ session, event });console.log('event',event);// const session = (await getUserSession(event)) || {};// console.log('2. User session retrieved:', { session });if(!session?.token){console.log('3. No token found in session');awaitclearUserSession(event);}// console.log('4. Verifying existing token');// const isValid = await verifyToken(session?.token);// console.log('5. Token validation result:', { isValid });// if (!isValid) {// console.log('6. Token is invalid, clearing session');// return await clearUserSession(event);// }console.log('7. Getting runtime config');construntimeConfig=useRuntimeConfig();console.log('8. Refreshing token');const{ token }=(await$fetch(`${runtimeConfig.public.DOMAIN_BACK_URL}/v2/auth/refresh-token`,{method: 'POST',headers: {
...(session?.token&&{authorization: session?.token,}),},},))||{};console.log('9. Token refresh result:',{hasToken: !!token});if(!token){console.log('10. No token received from refresh, redirecting to auth');returnsendRedirect(event,'/auth');}console.log('11. Verifying refreshed token');constisTokenValid=awaitverifyToken(token);console.log('12. Refreshed token validation result:',{ isTokenValid });if(!isTokenValid){console.log('13. Refreshed token is invalid, redirecting to auth');returnsendRedirect(event,'/auth');}console.log('14. Getting user from token');constuser=awaitgetUserFromToken(token);console.log('15. User from token:',{hasUser: !!user});if(user){console.log('16. Setting new user session');awaitsetUserSession(event,{
...session,user: user,token: token,});console.log('17. User session updated successfully');}else{console.log('18. No user found, clearing session');// await clearUserSession(event);throwcreateError({statusCode: 401,statusMessage: 'Session expired',});}}catch(error){console.log('19. Error in session hook:',{ error });// await clearUserSession(event);throwcreateError({statusCode: 401,statusMessage: 'Session expired',});}console.log('20. Setting extended session properties');session.extended={fromHooks: true,last_refresh: newDate(),};console.log('21. Session hook completed');});});
my nuxt.config.ts looks like this
runtimeConfig: { session: { maxAge: 60 * 60 * 24 * 365, // 365 days }, oauth: { google: { clientId: process.env.GOOGLE_OAUTH_CLIENT_ID, clientSecret: process.env.GOOGLE_OAUTH_CLIENT_SECRET, }, }, routeRules: { // some of my route are cached '/': { swr: true, cache: { maxAge: 3600, swr: true, } }, // 60 minutes '/auth': { swr: 86400 }, } ...
my header.vue using AuthState
`...<div
class="flex basis-full flex-row items-center justify-end gap-2 lg:flex"
Hey
I'm not 100% if the issue if the issue is on my end or not (and i'm having hard time to figuring it)
I can successfully log in with the module but me (and my users are randomly logged out)
It was working fine until a couple of week and i'm not able to identify the source of the issue and the pattern that triggers this
in my /server/plugin/session.ts
my nuxt.config.ts looks like this
runtimeConfig: { session: { maxAge: 60 * 60 * 24 * 365, // 365 days }, oauth: { google: { clientId: process.env.GOOGLE_OAUTH_CLIENT_ID, clientSecret: process.env.GOOGLE_OAUTH_CLIENT_SECRET, }, }, routeRules: { // some of my route are cached '/': { swr: true, cache: { maxAge: 3600, swr: true, } }, // 60 minutes '/auth': { swr: 86400 }, } ...
my header.vue using AuthState
`...<div
class="flex basis-full flex-row items-center justify-end gap-2 lg:flex"
not that i'm not using clearUserSession else, and only use clear() in the header for the user to logout
The nuxt-session cookie expires in 6 months, not 1 year (as set in nuxt config)
Thanks for the help 🙏
The text was updated successfully, but these errors were encountered: