Skip to content

Commit

Permalink
Merge pull request #576 from twilio-labs/prefill-timeout
Browse files Browse the repository at this point in the history
Decrease fetch timeout with API improvements
  • Loading branch information
pkamp3 authored Oct 30, 2024
2 parents 2f02613 + 5bb51da commit 9ae8532
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions verify-prefill/assets/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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...');
Expand All @@ -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
Expand Down Expand Up @@ -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}`);
Expand Down

0 comments on commit 9ae8532

Please sign in to comment.