Closed hitochan777 closed 7 months ago
Any update/workaround for the issue?
I'm using
"@sidebase/nuxt-auth": "0.7.1",
Until the PR is merged, you can apply patch to nuxt-auth with tools like patch-package (for npm) or pnpm patch
(for pnpm).
In my project, I use pnpm patch
that applies exactly the same code as the PR and it is working fine.
Well take a look into this today
Closed via #726
Environment
Build Modules: -
Reproduction
sign in (credentials)
Describe the bug
What is happening
I found that authentication state is lost on browser reload when the JWT is too long to fit in a cookie limit.
next-auth
splits a JWT token into multiple cookies when it is too long to fit in a single cookie. When I signin the following seems to occur.Browser sends a request to
/api/auth/callback/credentials
and the server returns a response with JWT token set to multiple Set-Cookie headers.Browser sends a request
/
and server responds with only oneSet-Cookie
header. But when carefully observed there are multiple cookies split by,
as its value. But browsers assumes text followed by,
as attribute for the first cookie. As you can see it the image below, the browser interpreted that there is only first chunk. And this makes cookies for JWT corrupted, which leads to unauthenticated state, I suppose.Why are multiple cookies merged into one
Set-Cookie
?During SSR the server calls session API to fetch session info, it then forwards Set-Cookie headers obtained from the API to the browser. When extracting Set-Cookie headers from the API the server uses
Headers.get("set-cookie")
, and it seems this method joins multiple Set-Cookie into one Set-Cookie.Possible solution
Instead of using
Headers.get
we can use Headers.getSetCookie. It returns an array of cookie values.Related: https://github.com/sidebase/nuxt-auth/issues/293
Additional context
No response
Logs