rp_st
02/01/2022, 12:50 PMgetServerSideProps
is:
js
try {
// getSession will do session verification for us
session = await Session.getSession(context.req, context.res)
} catch (err) {
if (err.type === Session.Error.TRY_REFRESH_TOKEN) {
// in this case, the session is still valid, only the access token has expired.
// The refresh token is not sent to this route as it's tied to the /api/auth/session/refresh API paths.
// So we must send a "signal" to the frontend which will then call the
// refresh API and reload the page.
return { props: { fromSupertokens: 'needs-refresh' } }
// or return {fromSupertokens: 'needs-refresh'} in case of getInitialProps
} else if (err.type === Session.Error.UNAUTHORISED) {
// user is logged out. Since this is for a protected route,
// we can simple send an empty prop object. Alternatively,
// you can pass anything else you would like here.
return { props: {} }
// or return {} in case of getInitialProps
} else {
throw err
}
}
So in the block for err.type === Session.Error.TRY_REFRESH_TOKEN
, instead of doing return { props: { fromSupertokens: 'needs-refresh' } }
, you can just do whatever else you want?