The accessToken isn't refreshed if it expires before the refreshToken
Environment
- Operating System:
Darwin - Node Version:
v23.9.0 - Nuxt Version:
3.15.4 - CLI Version:
3.21.1 - Nitro Version:
2.10.4 - Package Manager:
[email protected] - Builder:
- - User Config:
devtools,experimental,app,runtimeConfig,routeRules,build,vite,modules,hotjar,gtag,gtm,auth,eslint,pinia,i18n,imports,svgo,compatibilityDate - Runtime Modules:
@sidebase/[email protected],@nuxtjs/[email protected],[email protected],@vueuse/[email protected],@nuxt/[email protected],@nuxtjs/[email protected],@pinia/[email protected],[email protected],[email protected],[email protected] - Build Modules:
-
Reproduction
- use the local provider
- have your accessToken last less than your refreshToken
Describe the bug
The accessToken should be refreshed too once it expires instead of relying on the refresh token's expiration to be refreshed
Additional context
No response
Logs
I am facing the same problem :( Checking the source here, I think the reason is that it is watching the useState value instead of watching the cookie value.
FWIIW, I was using middleware getSession only with refresh Nuxt config enablePeriodically enabled. Everything works fine in that regard, except it's a bit obsessive for my portal needs. After disabling enablePeriodically, I run into this.
Changing app/middleware/get-session.ts to call refresh -- because it in turn calls session -- instead of directly calling getSession works for me:
export default defineNuxtRouteMiddleware((to, from) => {
const { getSession, refresh, signOut, status } = useAuth()
if (status.value !== 'unauthenticated') {
refresh().then((result) => {
console.log('get-session result:', result)
//getSession().then((result) => {
// console.log('get-session result:', result)
//})
}).catch((err) => {
console.error('get-session error:', err)
signOut({callbackUrl: 'logout', external: false})
})
}
//console.log(from, '->', to)
})