Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.
Defer Login
Mobile SDK hybrid apps
always present a Salesforce login
screen at startup. Sometimes, however, these apps can benefit from deferring authentication until
some later point.With a little configuration, you can defer login to any logical place in your
app.
Deferred login implementation with force.js is a two-step process:
- Configure the project to skip authentication at startup.
- In your JavaScript code, call the force.init() function, followed by the force.login() function, at the point where you plan to initiate authentication.
Step 1: Configure the Project to Skip Authentication
- In your platform-specific project, open the www/bootconfig.json file.
- Set the shouldAuthenticate property to “false”.
Step 2: Initiate Authentication in JavaScript
To initiate the authentication process, call the force.js
login() functions at the point of deferred login. The
force.init() method is usually necessary only for
testing or other non-production
scenarios.
The
force.login() function takes two arguments: a success
callback function and a failure callback function. If authentication fails, your failure
callback is invoked. If authentication succeeds, the force object
caches the access token in its oauth.access_token
configuration property and invokes your success callback.
1/* Do login */
2force.login(
3 function() {
4 console.log("Auth succeeded");
5 // Call your app’s entry point
6 // ...
7 },
8 function(error) {
9 console.log("Auth failed: " + error);
10 }
11);