I have an issue with refreshing tokens with Next'js & Nest.js. I have followed guide for Sessions with Server Components:
https://supertokens.com/docs/thirdparty/nextjs/app-directory/protecting-route#sessions-with-server-components--pre
Everything works fine until the access token expires and new one has to be issued. Then at this moment I receive an error that prevents anything from rendering.
Warning: Functions are not valid as a React child
Refreshing the page afterwards with a valid access token doesn't cause issue. This stacktrace also mentions
SessionAuth
component, which makes me suspect that it's problem with the SuperTokens itself.
Let me write this step by step what happens:
1. Refresh token epxires.
2. Browser sends two requests to:
/auth/session/refresh
and then
/auth/session/verify
(but not always). Response status codes are
200
3. While these requests happen, nothing is being rendered. These requests set the cookies accordingly. Error pasted below.
4. Refreshing site once again makes everyghing "just appear" and application behaves as desired.
I have tried lowering the time
ACCESS_TOKEN_VALIDITY
environment variable to a few seconds to make sure that it's the invalid access token that causes trouble.