fix(ui): hold recovery codes before the activation request

Activation ends the session while the reply is on its way, so a 401 elsewhere
in the page could leave before the codes arrived.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Lucas RayanandClaude Opus 5.5 committed 2026-11-05 06:27:39 -03:00
1 parent b9137e0948
commit 0e4e8cc37e
1 file changed
+11 -3
+11 -3
View File
@@ -196,12 +196,20 @@ function bindMfa() {
$('#mfaEnroll').addEventListener('submit', (event) => { $('#mfaEnroll').addEventListener('submit', (event) => {
event.preventDefault(); event.preventDefault();
attempt(status, async () => { attempt(status, async () => {
const reply = await withReauth(() => api('/api/auth/enroll/confirm', { // 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', method: 'POST',
body: { code: $('#mfaCode').value.trim() }, body: { code: $('#mfaCode').value.trim() },
})); }));
// This session has just ended, and the page must not leave with the codes. } catch (error) {
holdCodes(); releaseCodes();
throw error;
}
$('#mfaEnroll').hidden = true; $('#mfaEnroll').hidden = true;
$('#mfaQr').removeAttribute('src'); $('#mfaQr').removeAttribute('src');
$('#mfaKey').value = ''; $('#mfaKey').value = '';