Target file: frontend/nyaysetu-frontend/src/components/auth/FaceLoginModal.jsx
Description
- The biometric login flow starts a 45-second timeout when face scanning begins.
- The timeout callback captures the values of
step and faceDetected at the moment the timeout is created.
- The scanning state, being asynchronous in nature, can update after the moment timeout is captured, and timeout callback may still evaluate the outdated values when it executes.
- This can lead to incorrect timeout error even on successful authentication flow.
Current behavior
- The timeout callback depends on state values captured when scanning starts:
setTimeout(() => {
if (interval) clearInterval(interval);
if (step === 'scanning' && !faceDetected) {
setStep('error');
setMessage('Biometric timeout. Signal not acquired.');
}
}, 45000);
- Timeout callback relies on state values captured by the timeout closure.
- Outdated timeout callbacks can lead to an incorrect timeout flow.
Proposed Solution
- Manage the timeout lifecycle explicitly using a dedicated
ref variable.
- Store the timeout ID when scanning starts.
- Clear the timeout immediately when a valid face is detected.
- Ensure timeout execution only occurs while the current scan session is active.
Benifits
- Eliminates race conditions caused by stale closures.
- Improves reliability and predictability of the biometric login flow.
- Prevents intermittent, hard-to-reproduce authentication failures.
Additional details
Target file:
frontend/nyaysetu-frontend/src/components/auth/FaceLoginModal.jsxDescription
stepandfaceDetectedat the moment the timeout is created.Current behavior
Proposed Solution
refvariable.Benifits
Additional details