Server side rendering
#
AboutFor 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.
attemptRefreshingSession
function#
The - Via NPM
- Via Script Tag
import SuperTokens from 'supertokens-website';
await SuperTokens.attemptRefreshingSession();
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 totrue
, elsefalse
. - 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.