By default, the React Native SDK initializes with an API key. If your back end creates onboarding sessions and provides session tokens to your app, you can initialize the SDK without an API key and use the Sections API to run the flow.
Token-based setup is the recommended way to initialize the SDK. Instead of exposing your API key on the client side, your back end uses the key to create an onboarding session and returns a session token to the client. The client then uses that token to initialize the SDK and start onboarding for that specific session. This approach improves security by keeping your API key on the server and reducing the risk of unauthorized API access.
This setup is useful when your back end manages session creation, you want to avoid embedding an API key in your app, or you need session tokens that are scoped to individual users.
Initialize without an API key
Omit the key field from apiConfig:
try {
await IncodeSdk.initialize({
testMode: false,
apiConfig: {
url: 'YOUR_API_URL',
},
});
} catch (error) {
const e = error as IncodeSdkInitError;
console.error(`${e.code} - ${e.message}`);
}
Set up the session with a token
Pass the backend-created token to setupOnboardingSession:
const session = await IncodeSdk.setupOnboardingSession({
sessionConfig: {
token: 'YOUR_TOKEN',
},
});
Run the flow with sections
After the session is set up, use the Sections API to run the flow. Call startOnboardingSection() for each section, then finishOnboardingFlow() when all sections are complete:
await IncodeSdk.startOnboardingSection({
flowConfig: [
{ module: 'IdScan', showTutorial: false },
{ module: 'SelfieScan', showTutorial: false },
],
});
await IncodeSdk.faceMatch();
await IncodeSdk.finishOnboardingFlow();
For the full Sections API walkthrough, see Configure Flows Locally and Run Step by Step.