This SDK documentation is outdated. Please do not refer to it, and instead visit the User Guides section.

Skip to main content
Version: Next

Server side rendering

About#

For server side rendered apps, there will be instances when the access token has expired. In these cases, you need to use the refresh token to get a new access and a new refresh token.

However, the refresh token is only sent to one API endpoint - the refresh API. This means that for all other APIs, you will not have the refresh token as an input.

Therefore, for refreshing a session during SSR, we must first send a response that manually refreshes the session and then reloads the page.

The attemptRefreshingSession function#

import SuperTokens from 'supertokens-website';

await SuperTokens.attemptRefreshingSession();
  • Calling the above function will result in a call to your refresh API. If refreshing succeeds, this function will return a Promise that will resolve to true, else false.
  • If successful, you can automatically reload the page and the new access token will be sent to your API.
  • If unsuccessful, then you should redirect the user to the login page.
Looking for older versions of the documentation?
Which UI do you use?
Custom UI
Pre built UI