Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decrease fetch timeout with API improvements #576

Merged
merged 1 commit into from
Oct 30, 2024
Merged
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
Decrease fetch timeout with API improvements
robinske committed Oct 25, 2024
commit 5bb51dac2f3784bff3896ef72845ee1136393a64
8 changes: 4 additions & 4 deletions verify-prefill/assets/script.js
Original file line number Diff line number Diff line change
@@ -87,7 +87,7 @@ function displayUserData(data) {
document.getElementById('postal-code').innerText = data.postal_code;
}

async function fetchUserData(phoneNumber, verificationSid, waitTime = 15000) {
async function fetchUserData(phoneNumber, verificationSid, waitTime) {
try {
await wait(waitTime);
console.log('Attempting fetch...');
@@ -109,7 +109,7 @@ async function fetchUserData(phoneNumber, verificationSid, waitTime = 15000) {
console.log(`Fetching user data failed: ${result.message}`);
// Resursively call until we get a result...
if (maxCalls < 50) {
fetchUserData(phoneNumber, verificationSid, 3000);
fetchUserData(phoneNumber, verificationSid, 1000);
maxCalls += 1;
} else {
// eslint-disable-next-line no-alert
@@ -166,11 +166,11 @@ async function verifyOTP() {

if (result.success) {
console.log(
'Verification successful. Fetching user data every 15 seconds...'
'Verification successful. Fetching user data every 1 second...'
);
console.log(result.verificationSid);
displayLoadingSkeleton();
fetchUserData(phoneNumber, result.verificationSid);
fetchUserData(phoneNumber, result.verificationSid, 1000);
} else {
// eslint-disable-next-line no-alert
alert(`Verification failed: ${result.message}`);