Skip to content

clear TOTP QR code display in the demo app once enrollment is complete. #6984

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions packages/auth/demo/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ let selectedMultiFactorHint = null;
let recaptchaSize = 'normal';
let webWorker = null;
let totpSecret = null;
let totpDeadlineId = null;

// The corresponding Font Awesome icons for each provider.
const providersIcons = {
Expand Down Expand Up @@ -715,11 +716,11 @@ async function onStartEnrollWithTotpMultiFactor() {
);
// display the numbr of seconds left to enroll.
$('p.totp-deadline').show();
var id = setInterval(function () {
totpDeadlineId = setInterval(function () {
var deadline = new Date(totpSecret.enrollmentCompletionDeadline);
var t = deadline - new Date().getTime();
if (t < 0) {
clearInterval(id);
clearInterval(totpDeadlineId);
document.getElementById('totp-deadline').innerText =
'TOTP enrollment expired!';
} else {
Expand Down Expand Up @@ -756,12 +757,21 @@ async function onFinalizeEnrollWithTotpMultiFactor() {
try {
await multiFactor(activeUser()).enroll(multiFactorAssertion, displayName);
refreshUserData();
clearTOTPUIState();
alertSuccess('TOTP MFA enrolled!');
} catch (e) {
onAuthError(e);
}
}

function clearTOTPUIState() {
$('p.totp-deadline').hide();
$('img.totp-qr-image').hide();
$('p.totp-text').hide();
$('enroll-mfa-totp-verification-code').hide();
$('enroll-mfa-totp-display-name').hide();
clearInterval(totpDeadlineId);
}
/**
* Signs in or links a provider's credential, based on current tab opened.
* @param {!AuthCredential} credential The provider's credential.
Expand Down