For passwordless recipe implementation using web-j...
# support-questions-legacy
s
For passwordless recipe implementation using web-js-sdk It's not clear from the docs which fn should I use. There are multiple fn is SDK reference. So I'm just guessing from the fn names that probably these are all the steps/code I need to have for authentication 1. Create passwordless code -
superTokensPasswordless.createCode({ email: "john@example.org" })
2. Now either they will type in the code in a form I provide or they will visit the email link. If they visit the link, I will get their code like this
const userInputCode = superTokensPasswordless.getLinkCodeFromURL()
3. Then I will verify the code -
superTokensPasswordless.consumeCode({ userInputCode: "8465AWETA" }).then((res) => { if(res.createdUser){ console.log(JSON.stringify(res.user))} })
Session should be automatically set now Am I missing anything?
r
Hey! You are mostly correct. You don’t need to call the function to get the code from the url. The consume code function does that on its own
@nkshah2 can help here
n
Hey, When calling the consume code function if you don’t pass the user input code, the function will read it from the current url on its own
s
supertokensPasswordless is not defined
Getting this error. I have already imported the necessary packages both with tag
@0.1.3
and without it
Copy code
<script src="https://cdn.jsdelivr.net/gh/supertokens/supertokens-web-js/bundle/website.js"></script>
<script src="https://cdn.jsdelivr.net/gh/supertokens/supertokens-web-js/bundle/supertokens.js"></script>
<script src="https://cdn.jsdelivr.net/gh/supertokens/supertokens-web-js/bundle/session.js"></script>
<script src="https://cdn.jsdelivr.net/gh/supertokens/supertokens-web-js/bundle/emailpassword.js"></script>
n
You have not imported the passwordless script
s
This setup guide does not mention any passwordless script on frontend https://supertokens.com/docs/passwordless/quick-setup/frontend
n
Looks like the docs have it wrong,
Copy code
<script src="https://cdn.jsdelivr.net/gh/supertokens/supertokens-web-js/bundle/website.js"></script>
to
Copy code
<script src="https://cdn.jsdelivr.net/gh/supertokens/supertokens-web-js/bundle/website.js"></script>
<script src="https://cdn.jsdelivr.net/gh/supertokens/supertokens-web-js/bundle/passwordless.js"></script>
@sharma8471 Ive edited the snippet above to clarify, you need to add the import for both
website
and
passwordless
scripts
s
There are more issues with the doc - init fn is not shown in the setup guide
I can get the passwordless email now
But it has only the magic link. How can I get the code as well?
n
Docs for the supertokens-web-js are a work in progress at the moment
Can you enable debug logs on the backend and post the output here
s
Do I need to handle /auth/verify link or is it going to be handled by supertokens-node on it's own?
n
/auth/verify
is the link you receive in the email. This is something your frontend needs to handle
Its a frontend route that you need to create, on that route you would then call the create code function
s
Isn't this the link where we consume code? I used createCode when user gave me the email. Which sent this magic link to email.
n
Ah right my mistake, consume code is what I meant
s
Ok. I just did that. Created a route /auth/verify and called consumeCode there without any params. But I don't see the res.user
n
What is the full response object you received?
s
consume api response
{"status":"RESTART_FLOW_ERROR"}
I guess the code is consumed already.
n
Right this usually means you should start the whole process again
s
Not getting email again. /signingup/code request status 200
Btw, wouldn't it be better to consume code server side? Instead of putting the verify and then rerouting logic on frontend side. Server side has the best knowledge where to redirect the user after verficiation success or failure
Can I do that?
n
You would still need to call the verify functionality from the frontend because you need to create a session
Can you share a screenshot of the request made by the browser along with the response
7 Views