Skip to content

Fix deferred authentication callback bug in React Native Android#2863

Merged
wmathurin merged 2 commits intoforcedotcom:devfrom
wmathurin:fix/react-native-deferred-auth-callback
Apr 9, 2026
Merged

Fix deferred authentication callback bug in React Native Android#2863
wmathurin merged 2 commits intoforcedotcom:devfrom
wmathurin:fix/react-native-deferred-auth-callback

Conversation

@wmathurin
Copy link
Copy Markdown
Contributor

@wmathurin wmathurin commented Apr 4, 2026

Problem:
Callbacks from authenticate() were lost during OAuth flow when the activity paused for the OAuth browser and resumed after completion.

Solution:

  • Add pending callback instance variables to persist across activity lifecycle
  • Store callbacks in authenticate() before OAuth flow
  • Invoke callbacks in both authenticatedRestClient() (always runs) and onResume() (OAuth flow only)
  • Null check prevents double invocation

Store authentication callbacks across activity lifecycle to prevent loss
during OAuth flow. When authenticate() is called from React Native bridge,
the activity pauses to launch OAuth browser, then resumes after completion.
Previously, callbacks were lost during this pause/resume cycle.

Changes:
- Add instance variables to store pending callbacks
- Store callbacks in authenticate() before OAuth flow
- Invoke stored callbacks in onResume() after OAuth completes
- Clear callbacks after invocation or on auth failure

This fixes the issue where ReactNativeDeferredTemplate would show the
welcome screen after successful OAuth instead of loading contacts.
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 4, 2026

Codecov Report

❌ Patch coverage is 0% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.90%. Comparing base (007d98c) to head (d1e68cd).
⚠️ Report is 12 commits behind head on dev.

Files with missing lines Patch % Lines
...oidsdk/reactnative/ui/SalesforceReactActivity.java 0.00% 12 Missing and 1 partial ⚠️

❌ Your patch status has failed because the patch coverage (0.00%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@             Coverage Diff              @@
##                dev    #2863      +/-   ##
============================================
- Coverage     64.90%   64.90%   -0.01%     
- Complexity     2973     2974       +1     
============================================
  Files           222      222              
  Lines         17437    17449      +12     
  Branches       2487     2489       +2     
============================================
+ Hits          11318    11325       +7     
- Misses         4916     4920       +4     
- Partials       1203     1204       +1     
Components Coverage Δ
Analytics 47.92% <ø> (ø)
SalesforceSDK 59.83% <ø> (ø)
Hybrid 59.05% <ø> (ø)
SmartStore 78.20% <ø> (ø)
MobileSync 81.68% <ø> (ø)
React 51.50% <0.00%> (+0.11%) ⬆️
Files with missing lines Coverage Δ
...oidsdk/reactnative/ui/SalesforceReactActivity.java 26.05% <0.00%> (-2.93%) ⬇️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@wmathurin wmathurin marked this pull request as draft April 4, 2026 01:54
…enticated

When authenticate() is called and the user is already logged in, the
authenticatedRestClient callback is invoked immediately without triggering
an activity pause/resume cycle. Previously, callbacks were only invoked in
onResume(), which is not called in this scenario, causing callbacks to never
be invoked.

The fix ensures authenticatedRestClient() always invokes pending callbacks
immediately when a RestClient is obtained. For OAuth flows, either
authenticatedRestClient() or onResume() runs first (race condition) - whichever
runs first invokes callbacks and clears them, preventing double invocation.

This fix enables deferred authentication patterns in React Native where
authenticate() can be called multiple times without triggering OAuth if
already authenticated.
@wmathurin wmathurin merged commit 5122b1b into forcedotcom:dev Apr 9, 2026
17 of 20 checks passed
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.

2 participants