Skip to content

Commit 57f23d0

Browse files
Add init support for testing e2e test flow 2 with webauthn user changing email
1 parent 829bd75 commit 57f23d0

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

test/end-to-end/webauthn.accountlinking.test.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ import {
1818
setInputValues,
1919
setAccountLinkingConfig,
2020
getPasswordlessDevice,
21+
waitForUrl,
22+
changeEmail,
23+
getLatestURLWithToken,
2124
} from "../helpers";
2225
import { tryWebauthnSignUp } from "./webauthn.helpers";
2326
import assert from "assert";
@@ -48,6 +51,7 @@ describe("SuperTokens WebAuthn Account Linking", function () {
4851
"webauthn",
4952
"emailpassword",
5053
"passwordless",
54+
"emailverification",
5155
"session",
5256
"dashboard",
5357
"userroles",
@@ -134,4 +138,44 @@ describe("SuperTokens WebAuthn Account Linking", function () {
134138
"Different auth methods with same email should create separate users when account linking is disabled"
135139
);
136140
});
141+
142+
it("should handle email updates correctly for user that signed up with webauthn", async () => {
143+
await page.evaluate(() => window.localStorage.setItem("mode", "REQUIRED"));
144+
await setAccountLinkingConfig(false, false);
145+
const email = await getTestEmail();
146+
147+
await tryWebauthnSignUp(page, email);
148+
149+
// We should be in the confirmation page now.
150+
await submitForm(page);
151+
152+
await waitForUrl(page, "/auth/verify-email");
153+
154+
// we wait for email to be created
155+
await new Promise((r) => setTimeout(r, 1000));
156+
157+
// we fetch the email verification link and go to that
158+
const latestURLWithToken = await getLatestURLWithToken();
159+
await Promise.all([page.waitForNavigation({ waitUntil: "networkidle0" }), page.goto(latestURLWithToken)]);
160+
161+
// click on the continue button
162+
await Promise.all([submitForm(page), page.waitForNavigation({ waitUntil: "networkidle0" })]);
163+
await waitForUrl(page, "/dashboard");
164+
165+
await page.waitForTimeout(4000);
166+
167+
// Change the email for the webauthn user
168+
const recipeUserId = await page.evaluate(() => document.querySelector(".session-context-userId").textContent);
169+
const newEmail = getTestEmail("new");
170+
const res = await changeEmail("webauthn", recipeUserId, newEmail, null);
171+
172+
// Sign in with the new email
173+
await tryWebauthnSignIn(page);
174+
175+
// Since mode is required, user should be redirected to verify email
176+
// screen as the email was changed and the new email is not verified.
177+
await waitForUrl(page, "/auth/verify-email");
178+
179+
await page.waitForTimeout(4000);
180+
});
137181
});

test/server/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,11 @@ app.post("/changeEmail", async (req, res) => {
337337
email: req.body.email,
338338
phoneNumber: req.body.phoneNumber,
339339
});
340+
} else if (req.body.rid === "webauthn") {
341+
resp = await Webauthn.updateUserEmail({
342+
recipeUserId: convertToRecipeUserIdIfAvailable(req.body.recipeUserId),
343+
email: req.body.email,
344+
});
340345
}
341346
res.json(resp);
342347
});

0 commit comments

Comments
 (0)