Skip to content

Commit 6224e71

Browse files
committed
clear TOTP QR code display in the demo app once enrollment is complete.
1 parent 9c77f8f commit 6224e71

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

packages/auth/demo/src/index.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ let selectedMultiFactorHint = null;
100100
let recaptchaSize = 'normal';
101101
let webWorker = null;
102102
let totpSecret = null;
103+
let totpDeadlineId = null;
103104

104105
// The corresponding Font Awesome icons for each provider.
105106
const providersIcons = {
@@ -715,11 +716,11 @@ async function onStartEnrollWithTotpMultiFactor() {
715716
);
716717
// display the numbr of seconds left to enroll.
717718
$('p.totp-deadline').show();
718-
var id = setInterval(function () {
719+
totpDeadlineId = setInterval(function () {
719720
var deadline = new Date(totpSecret.enrollmentCompletionDeadline);
720721
var t = deadline - new Date().getTime();
721722
if (t < 0) {
722-
clearInterval(id);
723+
clearInterval(totpDeadlineId);
723724
document.getElementById('totp-deadline').innerText =
724725
'TOTP enrollment expired!';
725726
} else {
@@ -756,12 +757,21 @@ async function onFinalizeEnrollWithTotpMultiFactor() {
756757
try {
757758
await multiFactor(activeUser()).enroll(multiFactorAssertion, displayName);
758759
refreshUserData();
760+
clearTOTPUIState();
759761
alertSuccess('TOTP MFA enrolled!');
760762
} catch (e) {
761763
onAuthError(e);
762764
}
763765
}
764766

767+
function clearTOTPUIState() {
768+
$('p.totp-deadline').hide();
769+
$('img.totp-qr-image').hide();
770+
$('p.totp-text').hide();
771+
$('enroll-mfa-totp-verification-code').hide();
772+
$('enroll-mfa-totp-display-name').hide();
773+
clearInterval(totpDeadlineId);
774+
}
765775
/**
766776
* Signs in or links a provider's credential, based on current tab opened.
767777
* @param {!AuthCredential} credential The provider's credential.

0 commit comments

Comments
 (0)