Skip to content

Commit

Permalink
examlpe app fix (#807)
Browse files Browse the repository at this point in the history
* examlpe app fix

* test: fix with-phone-password-mfa

* docs: update test server in with-emailverification-then-password-thirdpartyemailpassword

* docs: update with-ev-with-otp example tests and check new version passes

* docs: revert testing change in example app

---------

Co-authored-by: Mihaly Lengyel <[email protected]>
  • Loading branch information
rishabhpoddar and porcellus authored Mar 19, 2024
1 parent dbbecb5 commit 5cbcc7d
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@ supertokens.init({
let email = input.formFields.filter((f) => f.id === "email")[0].value;
let password = input.formFields.filter((f) => f.id === "password")[0].value;

let response = await input.options.recipeImplementation.signUp({ email, password });
let response = await input.options.recipeImplementation.signUp({
email,
password,
userContext: input.userContext,
});
if (response.status === "EMAIL_ALREADY_EXISTS_ERROR") {
// if the input password is the fake password, and that's
// what's in the db too, then we shall treat this as a success,
Expand Down
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
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
2 changes: 1 addition & 1 deletion examples/with-phone-password-mfa/api-server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ supertokens.init({
framework: "express",
supertokens: {
// TODO: This is a core hosted for demo purposes. You can use this, but make sure to change it to your core instance URI eventually.
connectionURI: "http://localhost:3567",
connectionURI: "https://try.supertokens.com",
apiKey: "<REQUIRED FOR MANAGED SERVICE, ELSE YOU CAN REMOVE THIS FIELD>",
},
appInfo: {
Expand Down
2 changes: 1 addition & 1 deletion examples/with-phone-password-mfa/test/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe("SuperTokens Example Basic tests", function () {

browser = await puppeteer.launch({
args: ["--no-sandbox", "--disable-setuid-sandbox"],
headless: false,
headless: true,
});
page = await browser.newPage();
});
Expand Down
1 change: 1 addition & 0 deletions examples/with-phone-password/api-server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ supertokens.init({
input.userId,
input.recipeUserId,
input.tenantId,
input.accessTokenPayload,
input.userContext
),
phoneNumber: userInfo?.emails[0],
Expand Down

0 comments on commit 5cbcc7d

Please sign in to comment.