I have this ```EmailPasswordReact.init({ g...
# support-questions-legacy
f
I have this
Copy code
EmailPasswordReact.init({
        getRedirectionURL: async (context) => {
          if (context.action === "SUCCESS") {
            if (context.redirectToPath !== undefined) {
              // navigate back to where the user was before authenticated
              return context.redirectToPath;
            }
            return "/dashboard";
          }
          return undefined;
        },
r
Yea! you can return any path from this function and the user will be redirected to that path
f
hmm, where does the conditional come from?
If the user is not signed in, then the "add to cart" button forces them to sign in/sign up. After that, they need to be redirected back to "add to cart" page, makes sense?
otherwise, the signup/signin can just go to their dashboard.
If I "removed" the
Copy code
return /dashboard
, does the user get redirected back to where they came from by default?
r
when they click on add to cart and then get redirected, then
context.redirectToPath
should not be undefined.
f
so, how do I get them to go back to where they were pre-signin?
r
the value of
context.redirectToPath
should be where they were before. So it should take them there
f
so instead of
Copy code
return /dashboard
I should have
Copy code
return context.redirectToPath
right?
r
Thats already happening:
Copy code
if (context.redirectToPath !== undefined) {
              // navigate back to where the user was before authenticated
              return context.redirectToPath;
            }
f
ok, so just remove return /dashboard, right?
r
no really.
you redirect to /dashboard only when
context.redirectToPath === undefined
which is what you want
f
so, I leave the code as is? I thought it always redirects to dashboard right now
hmm
i'm checking
no it get's redirected do dashboard
*to
so, context.redirectdToPath has to be set somewhere, where?
useContext() ?
r
no it should be set on it's own. How have you implemented the part where the user clicks on the add to cart and gets redirected to the login screen?
f
actually, I haven't yet. I was just clicking "SignIn/Register" in header(my normal link) when I was on the addtocart page
r
i mean how do you redirect the user to the sign in page?
f
I have a button with a handler on it
Copy code
const handleAddToCart = () => {}
r
how do you redirect the user to the sign in page?
f
it's always available in the header of the site
r
im not sure i understand
f
the link to "SignIn"
r
do you manually redirect them?
or use the
redirectToAuth
function we provide?
f
Copy code
<Disclosure.Button
                          as="a"
                          href="/auth"
                          className={joinClassNames(
                            router.pathname === "signin"
                              ? "g-nav"
                              : "g-nav-hover",
                            "g-nav-user-dashboard-common block w-full text-left"
                          )}
                        >
                          Sign In/Register
                        </Disclosure.Button>
it's basically an href to /auth
r
right yea. That's why the redirectToPath is not set
you want to use redirectToAuth function that we provide
or change the href to
"/auth?redirectToPath=XYZ
where XYZ = the current path
f
I can do an
Copy code
onClick={redirectToAuth}
in a handler maybe?
that's not right there, I know
i'll check I see the docs on this
r
yes please.
f
thanks
got it, man you guys rock! supertokens is the shit
r
ThNks