From 9fbf1e8173378092ae706c8bed13c524c2d0aba9 Mon Sep 17 00:00:00 2001 From: rishabhpoddar Date: Sun, 30 Jun 2024 16:34:28 +0530 Subject: [PATCH] fixes passwordless login docs --- v2/passwordless/custom-ui/login-magic-link.mdx | 4 ++-- v2/passwordless/custom-ui/login-otp.mdx | 11 ++++++----- .../custom-ui/login-magic-link.mdx | 4 ++-- v2/thirdpartypasswordless/custom-ui/login-otp.mdx | 11 ++++++----- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/v2/passwordless/custom-ui/login-magic-link.mdx b/v2/passwordless/custom-ui/login-magic-link.mdx index 5bd2a70d0..0088ec43a 100644 --- a/v2/passwordless/custom-ui/login-magic-link.mdx +++ b/v2/passwordless/custom-ui/login-magic-link.mdx @@ -47,7 +47,7 @@ async function sendMagicLink(email: string) { /** * For phone number, use this: - let response = await ^{webJsCreatePasswordlessCode}({ + let response = await createCode({ phoneNumber: "+1234567890" }); @@ -87,7 +87,7 @@ async function sendMagicLink(email: string) { /** * For phone number, use this: - let response = await supertokens^{recipeNameCapitalLetters}.^{webJsCreatePasswordlessCode}({ + let response = await supertokens^{recipeNameCapitalLetters}.createCode({ phoneNumber: "+1234567890" }); diff --git a/v2/passwordless/custom-ui/login-otp.mdx b/v2/passwordless/custom-ui/login-otp.mdx index 4f76a15d6..6427032a7 100644 --- a/v2/passwordless/custom-ui/login-otp.mdx +++ b/v2/passwordless/custom-ui/login-otp.mdx @@ -86,7 +86,7 @@ async function sendOTP(email: string) { /** * For phone number, use this: - let response = await supertokens^{recipeNameCapitalLetters}.^{webJsCreatePasswordlessCode}({ + let response = await supertokens^{recipeNameCapitalLetters}.createCode({ phoneNumber: "+1234567890" }); @@ -330,17 +330,18 @@ When the user enters an OTP, you want to call the following API to verify it ```tsx -import supertokensPasswordless from "supertokens-web-js-script/recipe/passwordless"; +import { consumeCode, clearLoginAttemptInfo } from "supertokens-web-js/recipe/passwordless"; + async function handleOTPInput(otp: string) { try { - let response = await supertokensPasswordless.consumeCode({ + let response = await consumeCode({ userInputCode: otp }); if (response.status === "OK") { // we clear the login attempt info that was added when the createCode function // was called since the login was successful. - await supertokensPasswordless.clearLoginAttemptInfo(); + await clearLoginAttemptInfo(); if (response.createdNewRecipeUser && response.user.loginMethods.length === 1) { // user sign up success } else { @@ -361,7 +362,7 @@ async function handleOTPInput(otp: string) { // we clear the login attempt info that was added when the createCode function // was called - so that if the user does a page reload, they will now see the // enter email / phone UI again. - await supertokensPasswordless.clearLoginAttemptInfo(); + await clearLoginAttemptInfo(); window.alert("Login failed. Please try again"); window.location.assign("/auth") } diff --git a/v2/thirdpartypasswordless/custom-ui/login-magic-link.mdx b/v2/thirdpartypasswordless/custom-ui/login-magic-link.mdx index cf07822c6..15116c23c 100644 --- a/v2/thirdpartypasswordless/custom-ui/login-magic-link.mdx +++ b/v2/thirdpartypasswordless/custom-ui/login-magic-link.mdx @@ -47,7 +47,7 @@ async function sendMagicLink(email: string) { /** * For phone number, use this: - let response = await ^{webJsCreatePasswordlessCode}({ + let response = await createCode({ phoneNumber: "+1234567890" }); @@ -87,7 +87,7 @@ async function sendMagicLink(email: string) { /** * For phone number, use this: - let response = await supertokens^{recipeNameCapitalLetters}.^{webJsCreatePasswordlessCode}({ + let response = await supertokens^{recipeNameCapitalLetters}.createCode({ phoneNumber: "+1234567890" }); diff --git a/v2/thirdpartypasswordless/custom-ui/login-otp.mdx b/v2/thirdpartypasswordless/custom-ui/login-otp.mdx index 2e8f44080..93e712b1a 100644 --- a/v2/thirdpartypasswordless/custom-ui/login-otp.mdx +++ b/v2/thirdpartypasswordless/custom-ui/login-otp.mdx @@ -86,7 +86,7 @@ async function sendOTP(email: string) { /** * For phone number, use this: - let response = await supertokens^{recipeNameCapitalLetters}.^{webJsCreatePasswordlessCode}({ + let response = await supertokens^{recipeNameCapitalLetters}.createCode({ phoneNumber: "+1234567890" }); @@ -330,17 +330,18 @@ When the user enters an OTP, you want to call the following API to verify it ```tsx -import supertokensPasswordless from "supertokens-web-js-script/recipe/passwordless"; +import { consumeCode, clearLoginAttemptInfo } from "supertokens-web-js/recipe/passwordless"; + async function handleOTPInput(otp: string) { try { - let response = await supertokensPasswordless.consumeCode({ + let response = await consumeCode({ userInputCode: otp }); if (response.status === "OK") { // we clear the login attempt info that was added when the createCode function // was called since the login was successful. - await supertokensPasswordless.clearLoginAttemptInfo(); + await clearLoginAttemptInfo(); if (response.createdNewRecipeUser && response.user.loginMethods.length === 1) { // user sign up success } else { @@ -361,7 +362,7 @@ async function handleOTPInput(otp: string) { // we clear the login attempt info that was added when the createCode function // was called - so that if the user does a page reload, they will now see the // enter email / phone UI again. - await supertokensPasswordless.clearLoginAttemptInfo(); + await clearLoginAttemptInfo(); window.alert("Login failed. Please try again"); window.location.assign("/auth") }