Refactor QR refresh and status polling logic #518
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes:
On iOS, JavaScript polling of BankID’s /collect endpoint may pause while the user is in the BankID app and won’t always resume on return. Handling the polling on the server makes the authentication flow more robust, particularly if the returnUrl doesn’t return the user to the correct browser/app
High level overview of this PR:
Refactored QR code refresh to use
setIntervalfor periodic updates, replacing recursive timeouts. IntroducedstartQrCodeRefreshandstopQrCodeRefreshfor better control and cleanup.Rewrote status polling with an asynchronous loop, adding a
statusPollingActiveflag to prevent duplicate loops. Improved flow control for cancellation and completion states.Refactored
postJsonto use iterative retries, enhancing error handling for non-JSON responses and unknown errors.Improved type safety by using
string | nullfor nullable parameters and variables. Enhanced event listener handling with optional chaining for safer execution.Cleaned up redundant variables, consolidated logic, and added comments for better readability and maintainability. Updated UI visibility functions to handle
nulldisplay values gracefully.These things have been implemented (when relevant):