Next.js Discord

Discord Forum

Information set by middleware cookie not available in layout.js

Unanswered
Japanese cockle posted this in #help-forum
Open in Discord
Japanese cockleOP
My middleware.js is performing some authentication checks relating to access/refresh tokens. When an access token expires, it performs an exchange of a refresh token for a new access/refresh combo. If that succeeds, it continue on to the page.

However, in my layout.js I need to access information from those new minted tokens in order to pull the appropriate user/account information. But it looks like the cookies are not available using cookies() since they were set on the response in the Middleware, effectively meaning I won't be able to access them until the NEXT request.

How can I make sure the refreshed token set is available in the same run that the middleware refreshed them?

0 Replies