Reference documentation for authentication types and functions in the Agentforce Mobile SDK for React Native.
Overview
Authentication functions are exported directly from the package (not on the AgentforceService singleton):
import {
isEmployeeAgentAuthSupported,
isEmployeeAgentAuthReady,
hasEmployeeAgentSession,
loginForEmployeeAgent,
logoutEmployeeAgent,
getEmployeeAgentCredentials,
refreshEmployeeAgentCredentials,
} from "@salesforce/react-native-agentforce";
Auth Functions
These functions manage Employee Agent authentication.
isEmployeeAgentAuthSupported()
async function isEmployeeAgentAuthSupported(): Promise<boolean>;
Returns true if Mobile SDK auth bridge is available in this build.
isEmployeeAgentAuthReady()
async function isEmployeeAgentAuthReady(): Promise<boolean>;
Returns true if the user has valid credentials (active session).
hasEmployeeAgentSession()
async function hasEmployeeAgentSession(): Promise<boolean>;
Alias for isEmployeeAgentAuthReady(). Returns true if the user is currently logged in.
loginForEmployeeAgent()
async function loginForEmployeeAgent(): Promise<AuthCredentials>;
Launch the Mobile SDK OAuth login flow. Resolves with credentials on success.
Throws: Error if auth bridge unavailable, user cancels, or login fails.
logoutEmployeeAgent()
async function logoutEmployeeAgent(): Promise<void>;
Log out the current user via Mobile SDK. No-op if bridge unavailable.
getEmployeeAgentCredentials()
async function getEmployeeAgentCredentials(): Promise<AuthCredentials | null>;
Get current credentials if logged in; null otherwise.
refreshEmployeeAgentCredentials()
async function refreshEmployeeAgentCredentials(): Promise<AuthCredentials>;
Force a token refresh via Mobile SDK.
Throws: Error with REFRESH_FAILED, NOT_AVAILABLE, or NO_ACTIVITY.
AuthCredentials
interface AuthCredentials {
instanceUrl: string; // Salesforce instance URL
organizationId: string; // Org ID
userId: string; // User ID
accessToken: string; // Current OAuth access token
refreshToken?: string; // Refresh token (may not be available on all platforms)
}
Error Codes
Error codes thrown by the EmployeeAgentAuthBridge:
| Code | Source | Description |
|---|---|---|
NO_ACTIVITY |
login, refreshAuthCredentials (Android) | No current Activity available. |
NOT_AVAILABLE |
login, refreshAuthCredentials (Android) | Salesforce SDK not initialized. |
LOGIN_FAILED |
login (Android) | No credentials obtained after login flow. |
REFRESH_FAILED |
refreshAuthCredentials (Android) | No credentials available after refresh. |
ERROR |
Various (Android) | General error with message. |
Platform Availability
| Function | iOS | Android |
|---|---|---|
isEmployeeAgentAuthSupported() |
Yes (with WithMobileSDK) | Yes (with SalesforceReact) |
loginForEmployeeAgent() |
Yes | Yes |
logoutEmployeeAgent() |
Yes | Yes |
getEmployeeAgentCredentials() |
Yes | Yes |
refreshEmployeeAgentCredentials() |
Yes | Yes |
Employee Agent Config Exports
import {
EMPLOYEE_AGENT_ENABLED,
EMPLOYEE_AGENT_CONFIG,
isEmployeeAgentConfigValid,
} from "@salesforce/react-native-agentforce";
| Export | Type | Description |
|---|---|---|
EMPLOYEE_AGENT_ENABLED |
boolean |
Whether Employee Agent is enabled |
EMPLOYEE_AGENT_CONFIG |
EmployeeAgentConfig |
The Employee Agent configuration |
isEmployeeAgentConfigValid |
() => boolean |
Returns true if the config has required fields |