Hi, I previously already embedded the sign-up and...
# support-questions-legacy
k
Hi, I previously already embedded the sign-up and login form in a custom page. I'm now trying to embed the reset password form on a page as well. I'm following this guide here: https://supertokens.com/docs/emailpassword/common-customizations/reset-password/embed-in-page When I click on forgot password on the login page, it redirects back to the login page rather than the reset password page. I'm doing a console log inside of getRedirectionURL in frontendConfig and I see that the context is always
Copy code
{action: 'TO_AUTH', showSignIn: false}
Any guidance to get past this?
r
hey @kwadwon Have you embedded the reset password component in a route protected by SessionAuth? If so, then you should remove the SessionAuth wrapper around that route.
k
HI @rp_st -- no, the reset password component and the login component are both in routes that are not protected by SessionAuth. They are only wrapped by the SuperTokensWrapper
r
I see. That makes sense. Perhaps @porcellus can help here.
p
Hi, I think you are handling the getRedirectionURL of reset password in the wrong place: it should be handled by a callback passed to the EmailPassword recipe not at the root level. Please check here: https://supertokens.com/docs/emailpassword/common-customizations/reset-password/embed-in-page#step-b-on-the-frontend
I think you get redirected to the login page because the default url matches (or redirects you to) a protected page.
k
Ahh yes, I was handling getRedirectionURL on the root level instead of at the EmailPassword recipe level. I was able to get past that. Thank you. My last blocker is now around not being able to show the reset-password page when it's loaded. It works fine when it's on the client side (when I click the link from the login page to get to the reset password page). However, when I click the link from the email to get to the page, I'm seeing that no instance of an email password was found.
r
you need to make sure that you have called supertokens.init on the frontend on the global scope in your app
k
I saw in the documentation a comment in _app.tsx
Copy code
// we only want to call this init function on the frontend, so we check typeof window !== 'undefined'
So I have
Copy code
if (typeof window !== 'undefined') {
  // we only want to call this init function on the frontend, so we check typeof window !== 'undefined'
  SuperTokensReact.init(frontendConfig());
}
at the top of my _app.tsx file
r
Right. So you also need to make sure that the reset password component is not rendered on the server side.
You can do this using the dynamic HOC provided by NextJS
k
got it. thank you
When using SignInAndUp in my login page, is there additional work needed to redirect after successful login? I want to make sure I'm not using getRedirectionURL in the wrong place again. After successful login it doesn't redirection, it shows the view I have within the login page when doesSessionExist is true. I also don't see the getRedirectionURL getting called upon successful login. This is the same block where I have the reset password redirection just for context.
r
hmm. By default, it should redirect you to the
/
screen.
@porcellus can help here again
p
I've just stepped out for a bit, I'll check this out when I get back
k
thank you
the getRedirectionUrl for success is called on the auth recipe level, so you should be seeing that
but keep in mind, that this will only be called if you are not getting redirected to the email verification page
So if you've enabled email verification with the
REQUIRED
mode, then we get the url from the
getRedirectionUrl
of the email verification recipe
k
is how I have it set up right now. I'm able to login successfully. I don't have email verification required. I'm doing a console log in the redirectionURL to see if it's getting called. This is where I'm stuck -- trying to understand why it's not getting called.
p
that should be getting called. Just to be clear: you get redirected to "/" after a logging in, which is what you are trying to change?
k
I'm experiencing some inconsistency. My logging page is at http://localhost:3000/login when I have a successful login from there, I'm not redirected, it renders some text I have on that page for when the user session does exist. However, I have also seen a case, 1 time, where it redirected to /default.
p
"/default"? that's strange, in general we do not redirect to
/default
k
sorry, I meant /dashboard. But that happened one time. That is where I want it to go. However, it's not redirecting at all.
p
how are you embedding the sign in component?
k
I'm importing SignInAndUp component and rendering as part of my login page
p
I'm not a 100% sure, but it could be getting unmounted before the redirection happens.
Try and remove the alternate text, just show it anyway. It should redirect you as expected
k
The alternate text for the image?
p
No, the text you show when the user is logged in. Just always render the login page
k
Got it
Seems to have resolved it.
p
great. 🙂
k
So now it does redirect to "/" by default, whereas I'd like it to redirect to "/dashboard". I made the changes in getRedirectionURL as demonstrated in the documentation
p
so your getRedirectionUrl is still not getting called?
k
It's getting called -- It's because the page before login is "/" so after logging in, redirectToPath is an empty string rather than undefined so it returns back to "/" rather than /dashboard. I understand the flow.
I'm no longer blocked. Thank you for the help!
p
happy to help 🙂
3 Views