@verisoul_ai/react-native-verisoul
v0.4.64
Published
Verisoul helps businesses stop fake accounts and fraud
Downloads
599
Readme
React Native SDK
Verisoul provides a React Native SDK that allows you to implement fraud prevention in your cross-platform mobile applications. This guide covers the installation, configuration, and usage of the Verisoul React Native SDK.
To run the SDK a Verisoul Project ID is required. Schedule a call here to get started.
System Requirements
- React Native 0.60 or higher
- iOS 14.0 or higher
- Android API level 21 (Android 5.0) or higher
- For Expo projects: Expo SDK 45 or higher with custom development client
Installation
Using NPM
npm install @verisoul_ai/react-native-verisoulUsing Yarn
yarn add @verisoul_ai/react-native-verisoulAndroid Configuration
If an exception occurs during the build stating that the ai.verisoul:android package cannot be downloaded, add the following Maven repository inside your android/build.gradle file:
allprojects {
repositories {
// ...
maven { url = uri("https://us-central1-maven.pkg.dev/verisoul/android") }
}
}Expo Projects
Note: Requires custom development client (not supported in Expo Go)
1. Install expo-dev-client:
npx expo install expo-dev-client2. Configure app.json: add the plugin and set newArchEnabled to true
{
"expo": {
"newArchEnabled": true,
"plugins": ["@verisoul_ai/react-native-verisoul"]
}
}3. Install Verisoul SDK:
npm install @verisoul_ai/react-native-verisoul4. Prebuild and run:
npx expo prebuild --clean
npx expo run:android # or npx expo run:iosUsage
Initialize the SDK
The configure() method initializes the Verisoul SDK with your project credentials. This method must be called once when your application starts.
Parameters:
environment: The environment to useVerisoulEnvironment.prodfor production orVerisoulEnvironment.sandboxfor testingprojectId: Your unique Verisoul project identifier
Example:
import Verisoul, {
VerisoulEnvironment,
} from '@verisoul_ai/react-native-verisoul';
useEffect(() => {
Verisoul.configure({
environment: VerisoulEnvironment.prod, // or VerisoulEnvironment.sandbox
projectId: 'YOUR_PROJECT_ID',
});
}, []);When called, the Verisoul SDK will initialize its components, begin collecting device telemetry data, and prepare a session ID for fraud assessment.
getSessionId()
The getSessionID() method returns the current session identifier after the SDK has collected sufficient device data. This session ID is required to request a risk assessment from Verisoul's API.
Important Notes:
- Session IDs are short-lived and expire after 24 hours
- The session ID becomes available once minimum data collection is complete (typically within seconds)
- You should send this session ID to your backend, which can then call Verisoul's API to get a risk assessment
- A new session ID is generated each time the SDK is initialized or when
reinitialize()is called
Example:
const sessionId = await Verisoul.getSessionID();reinitialize()
The reinitialize() method generates a fresh session ID and resets the SDK's data collection. This is essential for maintaining data integrity when user context changes.
Example:
await Verisoul.reinitialize();After calling this method, you can call getSessionID() to retrieve the new session identifier.
Provide Touch Events
Touch event data is collected and analyzed to detect automated/bot behavior by comparing touch patterns with device sensor data. This helps identify anomalies that may indicate fraud.
React Native Setup:
Wrap your root component with VerisoulTouchRootView to automatically capture touch events across both iOS and Android:
import { VerisoulTouchRootView } from '@verisoul_ai/react-native-verisoul';
function App() {
return (
<VerisoulTouchRootView>{/* Your app components */}</VerisoulTouchRootView>
);
}iOS Configuration
For iOS-specific configuration including Device Check and App Attest setup, please refer to the iOS SDK Documentation.
Error Codes
The SDK throws VerisoulException with the following error codes:
| Error Code | Description | Recommended Action |
| ---------- | ----------- | ------------------ |
| INVALID_ENVIRONMENT | The environment parameter passed to Verisoul.configure() is invalid. Valid values are "dev", "sandbox", or "prod". | Ensure Verisoul.configure() parameter is exactly:• "dev", "sandbox", or "prod"• Case-sensitive• Free of whitespace |
| SESSION_UNAVAILABLE | A valid session ID could not be obtained. This typically occurs when Verisoul's servers are unreachable due to network blocking or a very slow connection. | • Implement exponential backoff.• Prompt user to check network or disable network blocker.• Log to identify blocking issues. |
| WEBVIEW_UNAVAILABLE | WebView is not available on the device. This can occur when WebView is disabled, missing, uninstalled, or corrupted on the device. | Prompt user to:• Enable WebView in settings• Update Android System WebView• Switch devices |
Exception Structure
All errors are thrown as VerisoulException with the following properties:
| Property | Type | Description | | -------- | ---------- | ------------------------------------------------------- | | code | String | One of the error codes above | | message | String | Human-readable error description | | cause | Throwable? | The underlying exception that caused the error (if any) |
Example
For a complete working example, see the example folder in this repository.
