MCPcopy Index your code
hub / github.com/firebase/quickstart-js / onEnrollVerifyCode

Function onEnrollVerifyCode

auth/mfa-password.ts:382–408  ·  view source on GitHub ↗

* Handles verify code button click for second factor enrollment. * @param {!Event} e The verify code for enrollment on click event.

(e: Event)

Source from the content-addressed store, hash-verified

380 * @param {!Event} e The verify code for enrollment on click event.
381 */
382function onEnrollVerifyCode(e: Event) {
383 e.preventDefault();
384 if (auth.currentUser && phoneVerificationId) {
385 const enrolVerificationCodeInput = document.getElementById(
386 'enroll-verification-code',
387 )! as HTMLInputElement;
388 const code = enrolVerificationCodeInput.value;
389 const credential = PhoneAuthProvider.credential(phoneVerificationId, code);
390 const multiFactorAssertion =
391 PhoneMultiFactorGenerator.assertion(credential);
392 const enrollDisplayNameInput = document.getElementById(
393 'enroll-display-name',
394 )! as HTMLInputElement;
395 const displayName = enrollDisplayNameInput.value || undefined;
396 // Enroll the phone second factor.
397 multiFactor(auth.currentUser)
398 .enroll(multiFactorAssertion, displayName)
399 .then(function () {
400 showAccountDetails(auth.currentUser!);
401 const enrolledFactors = multiFactor(auth.currentUser!).enrolledFactors;
402 showEnrolledFactors(enrolledFactors);
403 clearMfaDialog();
404 alertMessage('Second factor enrolled!');
405 })
406 .catch(displayMfaError);
407 }
408}
409
410/**
411 * Handles send code button click for second factor sign-in.

Callers

nothing calls this directly

Calls 4

showAccountDetailsFunction · 0.85
showEnrolledFactorsFunction · 0.85
clearMfaDialogFunction · 0.85
alertMessageFunction · 0.85

Tested by

no test coverage detected