Employee Agent Authentication in React Native

Learn how to authenticate users for Employee Agent mode using the Salesforce Mobile SDK integration or direct tokens.

Employee Agent authentication supports two approaches:

The Salesforce Mobile SDK handles the OAuth login flow natively. This is the recommended approach for production apps.

You provide an OAuth accessToken directly in the EmployeeAgentConfig. This is useful for development, testing, or when your app manages its own auth flow.

To use the Mobile SDK for authentication, configure your project for each platform.

Use the WithMobileSDK subspec in your Podfile:

This adds a dependency on SalesforceSDKCore, which provides OAuth login/logout flows, user account management, and token storage and refresh.

Add SalesforceReact as a runtime dependency in your android/app/build.gradle:

The bridge library declares SalesforceReact as compileOnly. Your host app must provide the dependency at runtime.

AgentforcePackage uses reflection to detect if SalesforceSDKManager is on the classpath. If found, EmployeeAgentAuthBridge is registered as a native module. If not, Employee Agent auth is gracefully disabled.

All auth functions are exported directly from the package:

Returns true if the build includes Mobile SDK and the EmployeeAgentAuthBridge native module is available. Use this to conditionally show/hide Employee Agent UI in your app.

Returns true if the user is currently logged in with valid credentials.

Launches the Mobile SDK's OAuth login flow. Returns AuthCredentials on success.

Logs out the current user via Mobile SDK. Clears stored credentials and tokens.

Returns the current auth credentials if the user is logged in, or null if no session exists.

Asks the Mobile SDK to refresh the current session and returns new credentials.

Here's a complete login flow for Employee Agent with Mobile SDK:

The SDK supports both automatic and manual token refresh.

The native SDK automatically fetches fresh tokens from the Mobile SDK when the current token expires. The UnifiedCredentialProvider on both platforms integrates with the Mobile SDK's user account system.

For scenarios where you need explicit control:

If you don't want to integrate the Mobile SDK but still need Employee Agent functionality, you can provide tokens directly:

In this mode:

  • isEmployeeAgentAuthSupported() returns false.
  • You're responsible for obtaining, storing, and refreshing tokens.
  • The native SDK won't automatically refresh the token.
  • When the token expires, the conversation may fail. You'll need to obtain a new token and call configure() again.

For development and testing, you can create a local configuration file that contains your Employee Agent settings and is not committed to source control.

Create src/config/employeeAgentConfig.local.ts:

The bridge package exports these constants and the validation function. If the local override file exists, its exports are used; otherwise, defaults are returned (EMPLOYEE_AGENT_ENABLED: false, empty config).

Add the file to your .gitignore:

For more details on these exports, see the Authentication Reference in the React Native SDK reference documentation.

Use these functions to check and manage the user's authentication session.

The Mobile SDK handles session persistence natively. Tokens are stored securely and survive app restarts. The EmployeeAgentAuthBridge delegates all storage to the Mobile SDK.