Is there a way to specify a redirect path after su...
# support-questions-legacy
p
Is there a way to specify a redirect path after successfully consuming a magic link? I dont see an option in
createMagicLink
method. I also tried appending
?redirectToPath=/path
to the end of the magic link but then the login fails. (500 from
signinup/code/consume
)
r
Hey. You shouldn’t get a 500. But it depends on how you added the query param.
But you should override the sendEmail function to modify link. Keep in mind that the link sends with a URL fragment (it’s a hash char followed by a string). Your extra query param has to come before the fragment.
p
I see. So yeah putting
redirectToPath
param before the hash char doesnt make it return a 500 but it still doesnt redirect with that. Looks like this if want to redirect to a route called /questions
http://localhost:4209/auth/verify?redirectToPath=%2Fquestions&rid=passwordless&preAuthSessionId=DIR6EFU4mOSjAQj4sf-_5t-3NgLk1xZlefuoQ7QvxiE=#Uww-g6ARcF8MJUUEP-qmLouRDzYcIlW3_0Q1t90EJ20=
So how would I modify the link to make it redirect after logging in? I guessi m not sure what
urlWithLinkCode
is supposed to do https://supertokens.com/docs/passwordless/common-customizations/change-magic-link-url
r
you should provide an impl to getRedirectionUrl in passwordless.init on the frontend: https://supertokens.com/docs/passwordless/pre-built-ui/auth-redirection#change-redirection-path-post-login And on success, read from the query param you added to redirect the user to the right page
p
The issue is that
context.redirectPath
is undefined though in the ovveride of
getRedirectionUrl
when I manually append
redirectToPath
on the magic link when generated. For some context, the magic link im generating outside of the login page to send in a notification and the deep link path is generated dynamically.
I think what I need to do is more similar to this https://supertokens.com/docs/passwordless/custom-ui/login-magic-link#changing-the-magic-link-url-or-deep-linking-it-to-your-app But not totally sure what urlWithLinkCode does
r
Well, even if it’s undefined, you can just read from the url directly in that function
p
oh I see, you mean getting it from window. Cause this works
Copy code
getRedirectionURL: async (context) => {
          if (context.action === 'SUCCESS') {
            const searchParams = new URLSearchParams(window.location.search);
            const redirectToPath = searchParams.get('redirectToPath');
            if (redirectToPath) {
              return redirectToPath;
            }
            return '/';
          }
          return undefined;
        },
r
Yup
p
Thatll work, thanks man!
r
great.
30 Views