near / fast-auth-signer

https://fast-auth-signer.vercel.app
MIT License
29 stars 8 forks source link

Improve account id fetch with race condition #181

Closed hcho112 closed 3 months ago

hcho112 commented 4 months ago

This PR contains implementation for improve UX of fetching account id.

As part of using web-authN passkey, we always given two sets of key-pairs and only one of them are genuine. We find the true one by checking its public key presence on firebase (main) AND kitwallet (fallback). The issue was that on previous implementation, we use Promise.allSettled to wait for both keys to be finished with checking with firebase + kitwallet. But the problem here is that, one of the key is falsy, in which it does not exist in firebase store, and therefore always hit kitwallet. As of now, kitwallet is the bottleneck of UX where it often takes VERY long to process or sometimes returns invalid result. Its performance is non-deterministic and ideally we should avoid depending on it as much as possible for now.

Solution on this PR is by having Promise.race to grap what gets returned first. Right now, out of given two keys, time taken to get genuine key is ALWAYS faster so once we receive it, we check for response with presence of account Id. If present, we return immediately, otherwise we also checks for second key just in case (but only if first one returns with empty)

Also there is an improvement on fetchAccountIds where it also uses Promise.race with wait duration of 10 seconds on kit wallet to response. If it doesn't return within 10 seconds, it will consider it as falsy and return empty. (If so, user will be redirected to email verification flow)

These changes will resolve one of two major bottleneck of fast-auth experience.

vercel[bot] commented 4 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
fast-auth-signer ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 20, 2024 3:32am