Skip to content

Functions

triggerAction

triggerAction(action, options?, locationConfig?, customAttributes?): Promise<TSSetActionResponse>

Reports a user action event and returns an action token. The action token should be passed to your backend to fetch risk recommendations via the Recommendation API.

Parameters

NameTypeDescription
actionstring | TSActionThe type of user action to report
options?TSActionEventOptionsAdditional context for the action event
locationConfig?ObjectControls location data collection for this action (see Track geolocation)
locationConfig.modestringOne of "disabled", "default", "forceCurrent", "forceLastKnown", "lastKnown"
locationConfig.validFor?numberFor "lastKnown" mode, return location only if not older than this many minutes
customAttributes?Record<string, any>Additional contextual data for the action; must match the schema defined in the Portal (see Custom attributes)

Returns

Promise<TSSetActionResponse>

Example

import { triggerAction, TSAction, TSClaimedUserIdType } from 'react-native-ts-accountprotection';

const response = await triggerAction(
  TSAction.login,
  {
    correlationId: "CORRELATION_ID",
    claimedUserId: "91e25bea0c...", // hashed email
    claimedUserIdType: TSClaimedUserIdType.email,
    referenceUserId: "REFERENCE_USER_ID"
  },
  { mode: "default" },
  { userLevel: "premium" }
);
const actionToken = response.actionToken;

setAuthenticatedUser

setAuthenticatedUser(userId): Promise<boolean>

Sets the user context for all subsequent events in the session (or until the user is explicitly cleared). It should be called only after you've fully authenticated the user (including, for example, any 2FA that was required).

Parameters

NameTypeDescription
userIdstringOpaque identifier of the user in your system

Returns

Promise<boolean>

Indicates if the call succeeded

Example

import { setAuthenticatedUser } from 'react-native-ts-accountprotection';

await setAuthenticatedUser(username);

clearUser

clearUser(): Promise<boolean>

Clears the user context for all subsequent events in the mobile session. The user is automatically cleared once the session expires or in case of a new login action.

Returns

Promise<boolean>

Indicates if the call succeeded

Example

import { clearUser } from 'react-native-ts-accountprotection';

await clearUser();

getSessionToken

getSessionToken(): Promise<string>

Returns a device session token that can be used to trigger action events via the Backend API. The session token binds user interactions to their device and is required for backend integrations. Call this after SDK initialization and before triggering events.

Returns

Promise<string>

The session token.

Example

import { getSessionToken } from 'react-native-ts-accountprotection';

const sessionToken = await getSessionToken();

logPageLoad

logPageLoad(pageName): Promise<void>

Tracks screen navigation events for behavioral data collection. Call this whenever the user navigates to a new screen in your app.

Parameters

NameTypeDescription
pageNamestringThe name of the screen or page the user navigated to

Returns

Promise<void>

Example

import { logPageLoad } from 'react-native-ts-accountprotection';

await logPageLoad("login-page");
await logPageLoad("dashboard");

setLogLevel

setLogLevel(isLogEnabled): Promise<void>

Enables or disables verbose SDK logging for debugging purposes.

Parameters

NameTypeDescription
isLogEnabledbooleanSet to true to enable debug logging

Returns

Promise<void>