Cookies in Middleware
Answered
Masai Lion posted this in #help-forum
Masai LionOP
Hi, I was storing accessToken and refreshToken in browser as cookies, and there is a dashboard page that uses them. However, the tokens need to be refreshed and the auth server is a seperate server, so in the middleware, I check the expiration date and invoke the refresh endpoint. The refresh endpoint responds with cookies as well. How do I forward these cookies to browser? So for example, initially in browser, Cookie A exists and user visit Dashboard. The cookie is refreshed from the remote endpoint and I want to store that new cookie in the client.
2 Replies
you can also use this: https://nextjs.org/docs/app/api-reference/functions/next-response#cookies