diff --git a/apps/gui/ui/account.js b/apps/gui/ui/account.js index 0782d03..5a50aba 100644 --- a/apps/gui/ui/account.js +++ b/apps/gui/ui/account.js @@ -196,12 +196,20 @@ function bindMfa() { $('#mfaEnroll').addEventListener('submit', (event) => { event.preventDefault(); attempt(status, async () => { - const reply = await withReauth(() => api('/api/auth/enroll/confirm', { - method: 'POST', - body: { code: $('#mfaCode').value.trim() }, - })); - // This session has just ended, and the page must not leave with the codes. + // Activation ends this session while the reply is on its way: a request + // from elsewhere in the page can get a 401 and leave before it lands, + // taking the codes with it. So the page is held before the POST. holdCodes(); + let reply; + try { + reply = await withReauth(() => api('/api/auth/enroll/confirm', { + method: 'POST', + body: { code: $('#mfaCode').value.trim() }, + })); + } catch (error) { + releaseCodes(); + throw error; + } $('#mfaEnroll').hidden = true; $('#mfaQr').removeAttribute('src'); $('#mfaKey').value = '';