Skip to content

Commit 5cbcc7d

Browse files
examlpe app fix (#807)
* 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]>
1 parent dbbecb5 commit 5cbcc7d

File tree

6 files changed

+31
-17
lines changed

6 files changed

+31
-17
lines changed

examples/with-emailverification-then-password-thirdpartyemailpassword/api-server.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,11 @@ supertokens.init({
9090
let email = input.formFields.filter((f) => f.id === "email")[0].value;
9191
let password = input.formFields.filter((f) => f.id === "password")[0].value;
9292

93-
let response = await input.options.recipeImplementation.signUp({ email, password });
93+
let response = await input.options.recipeImplementation.signUp({
94+
email,
95+
password,
96+
userContext: input.userContext,
97+
});
9498
if (response.status === "EMAIL_ALREADY_EXISTS_ERROR") {
9599
// if the input password is the fake password, and that's
96100
// what's in the db too, then we shall treat this as a success,

examples/with-emailverification-with-otp/api-server/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ supertokens.init({
3737
mode: "REQUIRED",
3838
}),
3939
MultiFactorAuth.init({
40-
firstFactors: ["thirdparty", "emailpassword"], // This is basically disallows using passwordless to sign in
40+
firstFactors: ["thirdparty", "emailpassword"], // This basically disallows using passwordless to sign in
4141
override: {
4242
functions: (oI) => ({
4343
...oI,

examples/with-emailverification-with-otp/test/basic.test.js

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@ const {
3030

3131
const SuperTokensNode = require("supertokens-node");
3232
const Session = require("supertokens-node/recipe/session");
33+
const Passwordless = require("supertokens-node/recipe/passwordless");
3334
const EmailVerification = require("supertokens-node/recipe/emailverification");
3435
const ThirdPartyEmailPassword = require("supertokens-node/recipe/thirdpartyemailpassword");
3536

3637
// Run the tests in a DOM environment.
3738
require("jsdom-global")();
3839

40+
const testOTP = "111111";
3941
const apiDomain = "http://localhost:3001";
4042
const websiteDomain = "http://localhost:3000";
4143
SuperTokensNode.init({
@@ -49,7 +51,12 @@ SuperTokensNode.init({
4951
websiteDomain: websiteDomain,
5052
appName: "testNode",
5153
},
52-
recipeList: [EmailVerification.init({ mode: "OPTIONAL" }), ThirdPartyEmailPassword.init(), Session.init()],
54+
recipeList: [
55+
EmailVerification.init({ mode: "OPTIONAL" }),
56+
Passwordless.init({ contactMethod: "EMAIL", flowType: "USER_INPUT_CODE" }),
57+
ThirdPartyEmailPassword.init(),
58+
Session.init(),
59+
],
5360
});
5461

5562
describe("SuperTokens Example Basic tests", function () {
@@ -82,20 +89,22 @@ describe("SuperTokens Example Basic tests", function () {
8289
]);
8390
await submitForm(page);
8491

85-
// Redirected to email verification screen
86-
await waitForSTElement(page, "#otp");
87-
92+
// Redirected to "email verification screen"
93+
await waitForSTElement(page, "[name=userInputCode]");
8894
const userId = await page.evaluate(() => window.__supertokensSessionRecipe.getUserId());
8995

90-
let otps = [];
91-
while (otps.length === 0) {
92-
const otpRes = await fetch("http://localhost:3001/test/otps");
93-
const res = await otpRes.json();
94-
otps = res.otps;
95-
}
96-
await setInputValues(page, [{ name: "otp", value: otps[0] }]);
97-
const submitBtn = await waitForSTElement(page, "#submitOtp");
98-
await submitBtn.click();
96+
const loginAttemptInfo = JSON.parse(
97+
await page.evaluate(() => localStorage.getItem("supertokens-passwordless-loginAttemptInfo"))
98+
);
99+
100+
await Passwordless.createNewCodeForDevice({
101+
tenantId: "public",
102+
deviceId: loginAttemptInfo.deviceId,
103+
userInputCode: testOTP,
104+
});
105+
106+
await setInputValues(page, [{ name: "userInputCode", value: testOTP }]);
107+
await submitForm(page);
99108

100109
const userIdElement = await page.waitForSelector("#userId");
101110
const userIdText = await page.evaluate((e) => e.innerText, userIdElement);

examples/with-phone-password-mfa/api-server/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ supertokens.init({
2222
framework: "express",
2323
supertokens: {
2424
// 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.
25-
connectionURI: "http://localhost:3567",
25+
connectionURI: "https://try.supertokens.com",
2626
apiKey: "<REQUIRED FOR MANAGED SERVICE, ELSE YOU CAN REMOVE THIS FIELD>",
2727
},
2828
appInfo: {

examples/with-phone-password-mfa/test/basic.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ describe("SuperTokens Example Basic tests", function () {
7575

7676
browser = await puppeteer.launch({
7777
args: ["--no-sandbox", "--disable-setuid-sandbox"],
78-
headless: false,
78+
headless: true,
7979
});
8080
page = await browser.newPage();
8181
});

examples/with-phone-password/api-server/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ supertokens.init({
197197
input.userId,
198198
input.recipeUserId,
199199
input.tenantId,
200+
input.accessTokenPayload,
200201
input.userContext
201202
),
202203
phoneNumber: userInfo?.emails[0],

0 commit comments

Comments
 (0)