Skip to content

Conversation

subhankarmaiti
Copy link
Contributor

This PR fixes issue #1278 where frequent CRYPTO_EXCEPTION errors were occurring on Android devices due to concurrent credential storage operations.

Why

The issue was caused by multiple concurrent calls to getCredentials() triggering unnecessary state updates and credential saves. When the same token was being stored multiple times concurrently, it led to crypto exceptions on Android devices.

The root cause was in the getCredentials method using the loginFlow wrapper, which would always save the credentials again.

How

  1. Added deep equality utility: Implemented a deepEqual function to compare user objects and detect actual changes
  2. Updated reducer: Added a new SET_USER action type that only updates state when the user object has actually changed (using deep equality comparison)
  3. Modified getCredentials behavior: Changed from using loginFlow wrapper to a direct implementation that:
    • Only dispatches SET_USER instead of LOGIN_COMPLETE
    • Avoids unnecessary credential saves when the user data hasn't changed
    • Prevents concurrent storage operations that were causing the crypto exceptions

Testing

  • Verified that the changes prevent unnecessary state updates when user data is unchanged
  • Confirmed that legitimate user updates still trigger state changes correctly
  • Tested that concurrent getCredentials calls no longer cause crypto exceptions

Closes #1278

@subhankarmaiti subhankarmaiti requested a review from a team as a code owner September 11, 2025 19:45
@subhankarmaiti subhankarmaiti changed the title fix concurrent credential storage errors by preventing unnecessary state updates fix: concurrent credential storage errors by preventing unnecessary state updates Sep 11, 2025
@pmathew92
Copy link
Contributor

Hi @subhankarmaiti , Were you able to reproduce the mentioned issue?
Do you think this needs to be addressed on the native layer and not just in the RN side ?
Since the native layer executes getCredentials in a singleExecutor , all calls to that should be in a sequential manner. Is that not happening in this scenario ?

@subhankarmaiti
Copy link
Contributor Author

subhankarmaiti commented Sep 12, 2025

@pmathew92, we can handle it on the native sdk as well and restrict to call saveCredentials concurrently.

@subhankarmaiti subhankarmaiti merged commit c85a6e8 into master Sep 12, 2025
3 checks passed
@subhankarmaiti subhankarmaiti deleted the fix/prevent-concurrent-credential-storage-errors branch September 12, 2025 08:18
NandanPrabhu added a commit that referenced this pull request Sep 29, 2025
* master:
  feat: add Claude Code PR Review workflow for enhanced pull request an… (#1317)
  feat: enhance Auth0Provider with platform-specific initialization and error handling (#1313)
  feat(web): Simplify Setup, Add Session Check & Fix Missing Refresh Token (#1303)
  Fix clearSession operation order to prevent premature user state clearing (#1309)
  Release v5.0.0-beta.6 (#1306)
  fix: concurrent credential storage errors by preventing unnecessary state updates (#1302)
  chore(deps): bump actions/checkout from 4 to 5 (#1272)
  chore(deps): bump actions/download-artifact from 4 to 5 (#1294)
  chore(deps): bump codecov/codecov-action from 5.5.0 to 5.5.1 (#1296)
  fix(docs): added back the docs folder (#1291)
  Release v5.0.0-beta.5 (#1290)
  fix(docs): organize exports into namespaces for better typedocs (#1269)
  fix: add missing clearSession native options (#1289)
  fix(android): add pathPrefix to Android manifest for proper App Links functionality (#1288)
  feat: add organization parameter support to resetPassword API (#1286)
  feat(auth): add `saveCredentials` method to `useAuth0` hook (#1285)
  feat: unify and improve error handling across platforms (#1261)
  chore(deps): bump codecov/codecov-action from 5.4.3 to 5.5.0 (#1279)
@subhankarmaiti subhankarmaiti mentioned this pull request Oct 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5.0.0-beta.4 – Frequent CRYPTO_EXCEPTION Errors on Android
2 participants