Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion frontend/src/features/auth/MFAEnrollmentBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ interface Copy {
* implementations of "are they required?" is how the banner and the guard end
* up disagreeing, and the one the user believes is the wrong one.
*/
export function copyFor(
function copyFor(
status: MFAStatus,
tr: (fr: string, en: string) => string,
/** Locale for the day count's plural form. Optional so existing callers hold. */
Expand Down
18 changes: 13 additions & 5 deletions frontend/src/features/auth/MFAPostAhaPrompt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,21 @@ export function MFAPostAhaPrompt() {
// alert and the server is already refusing requests. A modal on top of that
// is noise stacked on a blocker, not urgency.
const alreadyBlocked = status?.state === 'required';
const eligible = ahaReached && notConfigured && !alreadyBlocked;

// Decided while rendering, not in an effect (#878): the prompt opens on the
// render where the user becomes eligible, without a second render pass. The
// decision is taken once per transition into eligibility, as the effect did.
const [wasEligible, setWasEligible] = useState(false);
if (eligible !== wasEligible) {
setWasEligible(eligible);
if (eligible && !withinCooldown()) setOpen(true);
}

// Starting the cooldown is the side effect, and it stays in an effect.
useEffect(() => {
if (!ahaReached || !notConfigured || alreadyBlocked) return;
if (withinCooldown()) return;
setOpen(true);
localStorage.setItem(COOLDOWN_KEY, String(Date.now()));
}, [ahaReached, notConfigured, alreadyBlocked]);
if (open) localStorage.setItem(COOLDOWN_KEY, String(Date.now()));
}, [open]);

useEffect(() => {
if (!open) return;
Expand Down
Loading