React hook to manage polling on an Auth0 Advanced Customization of Universal Login (ACUL)
screen that waits for an out-of-band decision, such as an MFA push notification approval
or a pending consent.This hook sets up and controls a long-running polling loop that repeatedly checks
the current screen until one of the following occurs:
- The request is approved or denied by the user, triggering
options.onCompleted. - An error occurs (network error, non-200/429 response), triggering
options.onError. Polling then stops and does not retry. - The component unmounts or
stopPolling()is called, which cancels polling.
Key Features
isRunningis reactive — it updates automatically if the polling loop stops internally or is canceled.- Uses a stable single polling instance (
useRef) to prevent duplicate network calls and unintended restarts during React re-renders. - Automatic cleanup on unmount: no orphan timers or leaked XHR requests.
Parameters
Specifies the polling interval, success callback (
onCompleted), and optional error handler (onError).Returns
MfaPollingResult containing:isRunning—truewhile polling is active.startPolling()— starts or resumes polling.stopPolling()— stops polling immediately.
Supported Screens
mfa-push-challenge-pushreset-password-mfa-push-challenge-pushmfa-push-enrollment-qrpending-consent
Example
Remarks
- The
onErrorcallback receives an ULError object withstatusandresponseTextdescribing the server response. - Internal rate-limit responses (
429) are automatically handled: polling waits for the reset window before retrying. - Calling
startPolling()repeatedly while running is safe and idempotent.