Defer Login
Apps built with early versions of React Native for Mobile SDK always present a Salesforce login screen at startup. Sometimes, however, these apps can benefit from deferring authentication until some later point. Beginning with React Native for Mobile SDK 4.2, you can defer login to any logical place in your app.
Deferred login implementation is a two-step process:
- In your iOS or Android native container app, you call Mobile SDK native methods to disable authentication at startup.
- In your React code, you call a Mobile SDK JavaScript function at the point where you plan to initiate authentication.
Mobile SDK provides a React Native template app specifically to demonstrate deferred login: ReactNativeDeferredTemplate. To create an app based on this template, use the forcereact createwithtemplate
command, as follows:
Read on for the implementation details.
iOS (Objective-C):
To disable the Salesforce login screen from appearing at startup, open your project’s bootconfig.plist
file and set shouldAuthenticate
to false
.
Android (Java):
By default, the Salesforce login screen appears at startup. To disable this behavior, override the shouldAuthenticate()
method in your MainActivity
class (or whichever class subclasses SalesforceReactActivity
), as follows:
To initiate the authentication process, call the following oauth
function:
This function takes two arguments: a success callback function and a failure callback function. If authentication fails, your failure callback is invoked. If authentication succeeds, your success callback is invoked with a dictionary containing the following keys:
accessToken
refreshToken
clientId
userId
orgId
loginUrl
instanceUrl
userAgent
communityId
communityUrl