-
-
Notifications
You must be signed in to change notification settings - Fork 252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for Next.js middleware Edge Runtime #887
Comments
I believe a more generic solution could be to allow additional headers to be set along with the
and
and then from my middleware in next.js I can just:
|
A work-around would be to add this to your
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cookies are not properly accessed on the immediate Server Component render when set in Middlewares. The middlewares run on the Edge runtime, and although
set-cookie
headers are properly set, they are not directly available until the next time request headers are parsed. You can read more here: vercel/next.js#65008The issue this creates for me is that when I refresh my accessToken agains my external backend-api. The updated accessToken saved in the ironSession is not available on the immediate server-component fetch performed afterwards, triggering an additional refresh which is in turn denied due to refreshTokenReuseMitigation.
The solution made by Next.js team is to use a middleware header to merge in the headers to be "available in the same render that invoked middleware".
The header is
x-middleware-set-cookie
. I have tested this locally, and find a working solution by adding the said header with cookievalue whenever the correspondingx-middleware-next
header is present. Like so:The text was updated successfully, but these errors were encountered: