Not having updated cookies from middleware.ts until a page fully renders

Hi all, I'm having an issue with my middleware function, which handles refreshing auth tokens stored in cookies. here is the issue, if there access token has and have an refresh token it will request a new set of tokens A) expired B) doesn't exist when I set those cookies in the const res = NextResponse.next() and then set those cookies
const res = NextResponse.next();

res.cookies.set("access_token", { /* config */ })
res.cookies.set("refresh_token", { /* config */ })

return res;
const res = NextResponse.next();

res.cookies.set("access_token", { /* config */ })
res.cookies.set("refresh_token", { /* config */ })

return res;
when that page tries to render, if I immediately try to grab that access token in a server component I will always get undefined and after the page fully renders I now get that updated token in the cookie tab in the browser. My question is, is it possible to get the updated cookies from the headers before the page loads/fully renders or am I going to have to find a new solution to this problem? I thought about creating a wrapper server action that makes the refresh token request, but I feel like this is a job for the middleware. Any help is much appreciated. Thank you in advance!!
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server