diff --git a/examples/with-emailverification-with-otp/api-server/server.ts b/examples/with-emailverification-with-otp/api-server/server.ts index 5b08850bc..a3dcecafd 100644 --- a/examples/with-emailverification-with-otp/api-server/server.ts +++ b/examples/with-emailverification-with-otp/api-server/server.ts @@ -37,7 +37,7 @@ supertokens.init({ mode: "REQUIRED", }), MultiFactorAuth.init({ - firstFactors: ["thirdparty", "emailpassword"], // This is basically disallows using passwordless to sign in + firstFactors: ["thirdparty", "emailpassword"], // This basically disallows using passwordless to sign in override: { functions: (oI) => ({ ...oI, diff --git a/examples/with-emailverification-with-otp/package.json b/examples/with-emailverification-with-otp/package.json index 46c2dee5c..3bc12d8e9 100644 --- a/examples/with-emailverification-with-otp/package.json +++ b/examples/with-emailverification-with-otp/package.json @@ -20,7 +20,7 @@ "react-router-dom": "^6.3.0", "react-scripts": "^5.0.1", "supertokens-auth-react": "latest", - "supertokens-node": "latest", + "supertokens-node": "github:supertokens/supertokens-node#fix/allow_signup_with_unverified_session_user", "ts-node": "^10.8.0", "typescript": "^4.7.2", "web-vitals": "^2.1.4" diff --git a/examples/with-emailverification-with-otp/test/basic.test.js b/examples/with-emailverification-with-otp/test/basic.test.js index 4bb1bd98f..984194c65 100644 --- a/examples/with-emailverification-with-otp/test/basic.test.js +++ b/examples/with-emailverification-with-otp/test/basic.test.js @@ -30,12 +30,14 @@ const { const SuperTokensNode = require("supertokens-node"); const Session = require("supertokens-node/recipe/session"); +const Passwordless = require("supertokens-node/recipe/passwordless"); const EmailVerification = require("supertokens-node/recipe/emailverification"); const ThirdPartyEmailPassword = require("supertokens-node/recipe/thirdpartyemailpassword"); // Run the tests in a DOM environment. require("jsdom-global")(); +const testOTP = "111111"; const apiDomain = "http://localhost:3001"; const websiteDomain = "http://localhost:3000"; SuperTokensNode.init({ @@ -49,7 +51,12 @@ SuperTokensNode.init({ websiteDomain: websiteDomain, appName: "testNode", }, - recipeList: [EmailVerification.init({ mode: "OPTIONAL" }), ThirdPartyEmailPassword.init(), Session.init()], + recipeList: [ + EmailVerification.init({ mode: "OPTIONAL" }), + Passwordless.init({ contactMethod: "EMAIL", flowType: "USER_INPUT_CODE" }), + ThirdPartyEmailPassword.init(), + Session.init(), + ], }); describe("SuperTokens Example Basic tests", function () { @@ -82,20 +89,22 @@ describe("SuperTokens Example Basic tests", function () { ]); await submitForm(page); - // Redirected to email verification screen - await waitForSTElement(page, "#otp"); - + // Redirected to "email verification screen" + await waitForSTElement(page, "[name=userInputCode]"); const userId = await page.evaluate(() => window.__supertokensSessionRecipe.getUserId()); - let otps = []; - while (otps.length === 0) { - const otpRes = await fetch("http://localhost:3001/test/otps"); - const res = await otpRes.json(); - otps = res.otps; - } - await setInputValues(page, [{ name: "otp", value: otps[0] }]); - const submitBtn = await waitForSTElement(page, "#submitOtp"); - await submitBtn.click(); + const loginAttemptInfo = JSON.parse( + await page.evaluate(() => localStorage.getItem("supertokens-passwordless-loginAttemptInfo")) + ); + + await Passwordless.createNewCodeForDevice({ + tenantId: "public", + deviceId: loginAttemptInfo.deviceId, + userInputCode: testOTP, + }); + + await setInputValues(page, [{ name: "userInputCode", value: testOTP }]); + await submitForm(page); const userIdElement = await page.waitForSelector("#userId"); const userIdText = await page.evaluate((e) => e.innerText, userIdElement);