updateSession overrides maxAge
MarioC3 opened this issue · comments
Environment
I'm using nuxt:
- Operating System: Darwin
- Node Version: v18.14.2
- Nuxt Version: 3.7.3
- Nitro Version: 2.6.3
- Package Manager: yarn@3.2.4
- Builder: vite
- User Config: nitro, typescript, modules, i18n, experimental, propsDestructure, devtools, build, app, runtimeConfig, extends, tailwindcss, css, viewport, ogImage, routeRules
- Runtime Modules: @nuxtjs/i18n@8.0.0-rc.4-28257783.3664302, @nuxt/devtools@0.8.3, nuxt-lodash@2.5.0, @nuxtjs/tailwindcss@6.8.0, nuxt-icon@0.5.0, @vueuse/nuxt@10.4.1, @formkit/nuxt@1.0.0, @nuxtjs/google-fonts@3.0.2, @pinia/nuxt@0.4.11, nuxt-viewport@2.0.6, @nuxtjs/critters@0.5.0, nuxt-typed-router@3.3.1, v-lazy-show/nuxt, @unlazy/nuxt@0.10.1, nuxt-simple-robots@3.1.2, nuxt-simple-sitemap@3.3.4, nuxt-schema-org@2.2.0, @nuxtjs/html-validator@1.5.2
- Build Modules: -
Reproduction
I did my best to reproduce, but I'm not sure how StackBlitz handles cookies:
https://stackblitz.com/edit/nuxt-starter-pkgdcu?file=server%2Fapi%2Fsession.get.ts
Describe the bug
I set the cookie, with the maxAge at the beginning of the app, I update the session programatically without a maxAge
property with useSession
and the cookie max-age resets to session instead of honoring the maxAge that I added initially.
Additional context
No response
Logs
No response
The maxAge
property is relative to the time it is set, so to set it "correctly" when you update the cookie, the method would need to know how much time has passed since it was last set. That's not easily possible, so it just defaults to re-set the same maxAge
value again.
If you don't want to change the expiry of the cookie after it got first set, instead use expires
with a fixed date, and not the relative maxAge
.