Skip to content

Commit

Permalink
docs: update with-ev-with-otp example tests and check new version passes
Browse files Browse the repository at this point in the history
  • Loading branch information
porcellus committed Mar 19, 2024
1 parent 00ebbff commit a2bb07f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion examples/with-emailverification-with-otp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
35 changes: 22 additions & 13 deletions examples/with-emailverification-with-otp/test/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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 () {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit a2bb07f

Please sign in to comment.