I need to redirect to auth if a user is not logged...
# support-questions
m
I need to redirect to auth if a user is not logged in, I can use
ThirdPartyEmailPassword
to wrap my components but when I try to access a protected route including url search params, only the base of the route is send to the auth page as the redirectToPath and does not include my url search params. I'd prefer not to roll my own wrapper, so is there a way to configure
ThirdPartyEmailPassword
to include url search params in the redirectToPath? If not, I figure i have to create my own wrapper that checks if the user is logged in. I've tried importing
supertokens-website
into my NextJS app,
import SuperTokens from 'supertokens-website'
, however whenever I try to access
SuperTokens.doesSessionExist()
i get an error stating that SuperTokens is undefined. I have initialized SuperTokens in the _app.ts file. I can use
supertokens-auth-react
but not
supertokens-website
.
r
hey @mwill8886 can you open an issue about this please? We can add support for this. In the meantime however, you can use
<ThirdPartyEmailPasswordAuth requireAuth={false}>...</ThirdPartyEmailPasswordAuth>
This will allow your child component to render even if the user is not logged in, and in there, you can use the session context to see check if a user is not logged in and then redirect them to wherever you like with the query params intact.
m
Do you want me to open an issue on the github repo for
supertokens-website
?
r
on supertokens-auth-react
are you using supertokens-website?
or supertokens-auth-react?
m
so I tried accessing the context following the steps on here: https://supertokens.com/docs/thirdpartyemailpassword/common-customizations/sessions/checking-session-front-end
doesSessionExist
returns false even after sign up. We do have our own UI for the signup and login screens following: https://supertokens.com/blog/adding-social-login-to-your-website-with-supertokens I don't know if that's effecting it or not.
disregard last, I implemented it incorrectly at first. I changed it so I wrapped the entire app with
<ThirdPartyEmailPasswordAuth requireAuth={false}>
then checked the context in the individual pages. Now the context comes back correctly.
2 Views