Using Native Module
How to Use the CafSmartAuth Native Module in React Native
This detailed guide explains how to integrate the CafSmartAuth
native module into your React Native project using TypeScript. It includes creating a module and a custom hook to manage events and methods provided by the native SDK.
1. Create the module.ts
File
module.ts
FileThis file imports the native module and sets up a NativeEventEmitter
to handle events emitted by the module.
Example Implementation
2. Create the useSmartAuth.ts
Hook
useSmartAuth.ts
HookThis hook manages the events and state associated with the CafSmartAuth
module. It uses the moduleEventEmitter
to listen for events emitted by the native module.
Key Functions
formattedOptions
: Formats the settings sent to the native module into JSON format.useSmartAuth
: Hook that:Listens to events emitted by the native module.
Updates React state based on the events.
startSmartAuth
: Method to initiate authentication using the native module.requestLocationPermissions
: Method to request location permissions from the user.
Example Implementation
3. Available Methods
useSmartAuth
: A hook that provides the following states:success
: Information about successful authentications.error
: Details about errors that occurred.cancelled
: Indicates if the operation was cancelled.pending
: Information about pending authentications.isLoading
: Indicates if authentication is in progress.
startSmartAuth
: Method to start the authentication process.Parameters:
mfaToken
: Multi-factor authentication token.faceAuthToken
: Token for facial authentication.policyId
: ID of the authentication policy.personId
: ID of the person to authenticate.
requestLocationPermissions
: Method to request location permissions from the user (Android only).
4. Project Integration
Here is how to implement the hook in your project, follow SourceCode
Last updated