Hello, i'm trying to create a magic link that will...
# support-questions
r
Hello, i'm trying to create a magic link that will redirect to an URL (can be different on each magiclink), and without login page display. The magic link creation works, i have something like this (http://localhost:3000/dashboardhttp://localhost:3000/auth/verify?rid=passwordless&preAuthSessionId=*******) And I have this code on my front :
Copy code
getRedirectionURL: async (context) => {
                if (context.action === "SUCCESS") {
                    if (context.redirectToPath !== undefined) {
                        // we are navigating back to where the user was before they authenticated
                        return context.redirectToPath;
                    }
                    return "/dashboard";
                }
                return undefined;
            }
but I don't see how to pass the
redirectToPath
to get it here Thanks for your help 🙂
r
hey @Romain
Just so i understand, you want to redirect the user to a custom location based on a query param in the magic link?
r
Yes 🙂
r
So you can modify the magic link to add a custom query param to it when you are sending it. Then in the
getRedirectionURL
function, if
context.action === "SUCCESS"
, you can read that query param using
window.location.search
and redirect the user to that page.
r
Okay i will try it, thanks ! Just for curiosity, the
context.redirectToPath
is used for what ? And where is setted ?
r
So if a user visits /home and that redirects them to /auth (cause they need to be logged in to see /home), then our SDK sets the redrectToPath to be /home so that after they login, they are redirected to the correct place.
r
Oh okay, well
thanks for your help
And last question, you know why I have an error when i used a magic link ?
r
what does the network tab say in inspect element?
r
/auth/signinup/code/consume 500
in my backend
I miss a recipe initialisation ?
r
hmm. And what is the error on your backend? Are you logging the error?
naa.. if you missed a recipe initialisation, then it would have given 404
r
Copy code
SuperTokens core threw an error for a POST request to path: '/recipe/signinup/code/consume' with status code: 400 and message: Input encoding error in linkCode
I found, it was the params
&redirectPath=/test
, I move it to the start of the URL
r
ah right.. you need to add it to the Query param part of the URL, not just the end of it. Cause the URL has a fragment at the end of it which is the code for the magic link
r
And the params is loose on the action success, because there is two redirect. I'll try some things, I'll stop bothering you, thanks 😉
Just the error
PARAMS ->  ?rid=passwordless&error=restart_link
on success is normal
?
r
well.. you should'nt get that on success
error=restart_link
should not be there
r
Ah 🤔
But the login work 🤷‍♂️
r
im not sure what the situation is for you. You're going to have to give more info about what modification you are doing and what worked and what not.
r
Everything work, i'm logged, but when I log the
window.location.search
is have this error
r
which error?
&error=restart_link
?
r
Yes
I think it's when i'm already logged and i use the magiclink again
r
yea.. then it's possible
try logging out and creating a new magic link
and doing the flow again
r
Yeah it seems that is was this
Do we agree that if I create a magic link with an email of a user already in base, it should use the same userId and not create a new one?
r
yea. it should
i mean it should use the same userID
r
yes well
r
as long as that user had used magic link to sign up
if they used social login to sign up, it will create a new user ID
r
Ah it's the same for password email signup user ? And passwordless user ?
It's not possible to link to the same userId every user with the same email ?
r
It is. But you will have to do that linking yourself at the moment via the override features we have. We have an example app for account linking: https://github.com/supertokens/supertokens-auth-react/tree/master/examples/with-thirdpartyemailpassword-passwordless
r
Okay i will check it, thanks !
2 Views