kuba_huba
02/23/2024, 5:28 PMSessionAuthForNextJS
- if I perform all the checks (error, session, hasToken claims etc.) then do I still need to wrap my page with <SessionAuthForNextJS />
as [shown in the docs](https://supertokens.com/docs/thirdpartyemailpassword/nextjs/app-directory/protecting-route#using---presessionauthfornextjs-and-checking-for-sessions--pre) ? If so, why is that? I understand that it will handle the redirects appropriately (written in the docs), but isn't it a bit redundant? It's already used in the checks before the page is returned.
This fragment of code says:
tsx
// `session` will be undefined if it does not exist or has expired
if (!session) {
// component is returned within these checks
}
Then the comment above the final return statement says roughly the same:
tsx
/**
* SessionAuthForNextJS will handle proper redirection for the user based on the different session states.
* It will redirect to the login page if the session does not exist etc.
*/
return (
<SessionAuthForNextJS>
<div>
Your user id is: {session.getUserId()}
</div>
</SessionAuthForNextJS>
);
To my understanding it would be impossible to reach this code in case of a non-existent session, since we check for it beforehand. Why wrap the page then? Are there different states of session that are not handled by all of the checks before?SuperTokens is an open source authentication solution offering features like: Different types of login: Email / password, Passwordless (OTP or Magic link based).
Powered by