Unverified Commit 90ddc248 authored by Rishabh Poddar's avatar Rishabh Poddar Committed by GitHub

(with-supertokens example): Fixes infinite redirect issue for unauthorised error…

(with-supertokens example): Fixes infinite redirect issue for unauthorised error during SSR (#42634)

If there is an unauthorised error during `getServerSideProps`, then we
return the same response as the try refresh token error so that all
cookies are cleared from the frontend due to refreshing failure.

If we did not do this, it would cause an infinite loop if the session
was removed in offline mode as the frontend would still think that the
session exists, and would redirect back to the protected route which
would fail verification again.
parent 5af7af5f
......@@ -20,10 +20,11 @@ export async function getServerSideProps(context) {
} catch (err) {
if (err.type === Session.Error.TRY_REFRESH_TOKEN) {
return { props: { fromSupertokens: 'needs-refresh' } }
} else if (
err.type === Session.Error.UNAUTHORISED ||
err.type === Session.Error.INVALID_CLAIMS
) {
} else if (err.type === Session.Error.UNAUTHORISED) {
// this will force the frontend to try and refresh which will fail
// clearing all cookies and redirecting the user to the login screen.
return { props: { fromSupertokens: 'needs-refresh' } }
} else if (err.type === Session.Error.INVALID_CLAIMS) {
return { props: {} }
} else {
throw err
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment