@@ -18,6 +18,9 @@ import {
1818 setInputValues ,
1919 setAccountLinkingConfig ,
2020 getPasswordlessDevice ,
21+ waitForUrl ,
22+ changeEmail ,
23+ getLatestURLWithToken ,
2124} from "../helpers" ;
2225import { tryWebauthnSignUp } from "./webauthn.helpers" ;
2326import 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} ) ;
0 commit comments