feat(auth): cache password policy per-app in validatePassword #8779
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.
Cache the fetched password policy per Firebase app to avoid
redundant API calls to the identity toolkit endpoint.
Description
Every time you call validatePassword(), the library was making an API call to Firebase's Identity Toolkit
to fetch the password policy. When a user types their password character by character (e.g.,
"P-a-s-s-w-o-r-d-1-2-3-$"), that's 12 API calls just for one password entry. If users backspace and
retype, it adds up fast.
Firebase has rate limits on this endpoint, so you hit:
QUOTA_EXCEEDED: Exceeded quota for getting password policy
Why Debounce Didn't Help
Debouncing reduces the frequency of calls, but the real issue is that the password policy never changes
during a user session. It's static configuration set in Firebase Console. Even one call per password field
interaction is wasteful when you could just fetch it once.
The Fix
Cache the password policy after the first fetch:
The policy only changes when an admin updates it in Firebase Console, which is rare. So caching it for the
lifetime of the app session is safe and eliminates the quota issue entirely.
Per-App Cache
If your app uses multiple Firebase projects, each app gets its own cached policy (keyed by auth.app.name),
since different projects could have different password requirements.
Related issues
#8780
Release Summary
Fixed
validatePassword()causingQUOTA_EXCEEDEDerrors by caching the password policyper-app. The policy is now fetched once and reused for subsequent validations.
Checklist
AndroidiOSOther(macOS, web)e2etests added or updated inpackages/\*\*/e2e(no e2e behaviour changed)jesttests added or updated inpackages/\*\*/__tests__Test Plan
TBC - I've implemented this in my code by editing the library directly in node-modules, and it worked.
I still have to set up tests to run properly. (I'm hoping that there are some automated runners that would do that for me ;)
Think
react-native-firebaseis great? Please consider supporting the project with any of the below:React Native FirebaseandInvertaseon Twitter