Skip to content

Commit

Permalink
fixes passwordless login docs
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabhpoddar committed Jun 30, 2024
1 parent e049405 commit 9fbf1e8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
4 changes: 2 additions & 2 deletions v2/passwordless/custom-ui/login-magic-link.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async function sendMagicLink(email: string) {
/**
* For phone number, use this:
let response = await ^{webJsCreatePasswordlessCode}({
let response = await createCode({
phoneNumber: "+1234567890"
});
Expand Down Expand Up @@ -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"
});
Expand Down
11 changes: 6 additions & 5 deletions v2/passwordless/custom-ui/login-otp.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
});
Expand Down Expand Up @@ -330,17 +330,18 @@ When the user enters an OTP, you want to call the following API to verify it
<TabItem value="npm">

```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 {
Expand All @@ -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")
}
Expand Down
4 changes: 2 additions & 2 deletions v2/thirdpartypasswordless/custom-ui/login-magic-link.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async function sendMagicLink(email: string) {
/**
* For phone number, use this:
let response = await ^{webJsCreatePasswordlessCode}({
let response = await createCode({
phoneNumber: "+1234567890"
});
Expand Down Expand Up @@ -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"
});
Expand Down
11 changes: 6 additions & 5 deletions v2/thirdpartypasswordless/custom-ui/login-otp.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
});
Expand Down Expand Up @@ -330,17 +330,18 @@ When the user enters an OTP, you want to call the following API to verify it
<TabItem value="npm">

```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 {
Expand All @@ -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")
}
Expand Down

0 comments on commit 9fbf1e8

Please sign in to comment.