---
title: React Native
description: Integrate the Human Token Journey into your React Native app — ASWebAuthenticationSession on iOS and Custom Tabs on Android via a native module.
canonical: https://developer.unico.io/human-plugin/integrations/app/react-native
locale: en
generated_by: markdown-export
---

React Native

Integrate the Human Token Journey into your React Native app via a native module.

The integration uses a native module that delegates to `ASWebAuthenticationSession` on iOS and Custom Tabs on Android. When the journey finishes, the native module resolves the promise with the callback URL.

### Prerequisites

- React Native 0.71 or later
- Xcode 14+ for iOS
- Android Studio for Android
- A unique URL scheme for your app (e.g. `myapp`)

### Step 1: Define your URL scheme

Choose a unique scheme (e.g. `myapp`). This is used as the `callbackUri` when creating the process:

```text
callbackUri: myapp://callback
```

Create the process with the Human Plugin API and send this value as `callbackUri`. See [Create a process](/human-plugin/api-reference/create-process).

### Step 2: Create the TypeScript bridge

```typescript
// src/modules/UnicoModule.ts
import { NativeModules } from 'react-native';

const { UnicoModule } = NativeModules;

if (!UnicoModule) {
  throw new Error('UnicoModule not found. Make sure the native module is linked correctly.');
}

export const Unico = {
  openSession: (url: string): Promise<string> => UnicoModule.openSession(url),
};
```

### Step 3: Implement the iOS native module

- Objective-C bridge
- Swift implementation

```objc
// ios/UnicoModule.m
#import <React/RCTBridgeModule.h>

@interface RCT_EXTERN_MODULE(UnicoModule, NSObject)
RCT_EXTERN_METHOD(openSession:(NSString *)url
                  resolve:(RCTPromiseResolveBlock)resolve
                  reject:(RCTPromiseRejectBlock)reject)
@end
```

```swift
// ios/UnicoModule.swift
import AuthenticationServices

@objc(UnicoModule)
class UnicoModule: NSObject, ASWebAuthenticationPresentationContextProviding {

    private var session: ASWebAuthenticationSession?

    @objc func openSession(_ url: String,
                           resolve: @escaping RCTPromiseResolveBlock,
                           reject: @escaping RCTPromiseRejectBlock) {
        guard let sessionURL = URL(string: url) else {
            reject("INVALID_URL", "Invalid URL", nil)
            return
        }
        DispatchQueue.main.async {
            let newSession = ASWebAuthenticationSession(
                url: sessionURL,
                callbackURLScheme: "myapp"
            ) { callbackURL, error in
                self.session = nil
                if let callbackURL = callbackURL {
                    resolve(callbackURL.absoluteString)
                } else {
                    reject("SESSION_ERROR", error?.localizedDescription ?? "Session cancelled", error)
                }
            }
            newSession.presentationContextProvider = self
            newSession.prefersEphemeralWebBrowserSession = true
            newSession.start()
            self.session = newSession
        }
    }

    func presentationAnchor(for session: ASWebAuthenticationSession) -> ASPresentationAnchor {
        guard let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
              let window = windowScene.windows.first else {
            return ASPresentationAnchor()
        }
        return window
    }

    @objc static func requiresMainQueueSetup() -> Bool { return true }
}
```

### Step 4: Implement the Android native module

Add the dependency to `android/app/build.gradle`:

```groovy
implementation("androidx.browser:browser:1.5.0")
```

```kotlin
// android/app/src/main/java/<your.package>/UnicoModule.kt
package com.yourapp

import android.content.Intent
import android.net.Uri
import androidx.browser.customtabs.CustomTabsIntent
import com.facebook.react.bridge.*

class UnicoModule(private val reactContext: ReactApplicationContext) :
    ReactContextBaseJavaModule(reactContext) {

    private var pendingPromise: Promise? = null

    override fun getName() = "UnicoModule"

    @ReactMethod
    fun openSession(url: String, promise: Promise) {
        pendingPromise = promise
        currentActivity?.runOnUiThread {
            CustomTabsIntent.Builder().build()
                .launchUrl(currentActivity!!, Uri.parse(url))
        } ?: promise.reject("NO_ACTIVITY", "No current activity")
    }

    fun handleRedirectUrl(uri: Uri) {
        if (uri.scheme == "myapp") {
            pendingPromise?.resolve(uri.toString())
            pendingPromise = null
        }
    }
}
```

```kotlin
// UnicoPackage.kt
package com.yourapp

import com.facebook.react.ReactPackage
import com.facebook.react.bridge.NativeModule
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.uimanager.ViewManager

class UnicoPackage : ReactPackage {
    override fun createNativeModules(ctx: ReactApplicationContext): List<NativeModule> =
        listOf(UnicoModule(ctx))
    override fun createViewManagers(ctx: ReactApplicationContext): List<ViewManager<*, *>> =
        emptyList()
}
```

Register in `MainApplication.kt`:

```kotlin
override fun getPackages(): List<ReactPackage> =
    PackageList(this).packages.apply {
        add(UnicoPackage())
    }
```

Handle redirects in `MainActivity.kt`:

```kotlin
override fun onNewIntent(intent: Intent) {
    super.onNewIntent(intent)
    intent.data?.let { uri ->
        if (uri.scheme == "myapp") {
            val module = reactInstanceManager
                .currentReactContext
                ?.getNativeModule(UnicoModule::class.java)
            module?.handleRedirectUrl(uri)
        }
    }
}
```

### Step 5: Configure AndroidManifest.xml

```xml
<uses-feature android:name="android.hardware.camera" android:required="false" />
<uses-permission android:name="android.permission.CAMERA" />

<activity android:name=".MainActivity" ...>
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="myapp" android:host="callback" />
    </intent-filter>
</activity>
```

### Step 6: Launch the journey

```typescript
import { Unico } from './modules/UnicoModule';

const resultUrl = await Unico.openSession(processLink);
// resultUrl = myapp://callback?id=...
```

### File summary

| File | Purpose |
| --- | --- |
| `src/modules/UnicoModule.ts` | TypeScript bridge |
| `ios/UnicoModule.m` | Objective-C declaration |
| `ios/UnicoModule.swift` | iOS — ASWebAuthenticationSession |
| `android/.../UnicoModule.kt` | Android — Custom Tabs |
| `android/.../UnicoPackage.kt` | Package registration |
| `android/.../MainApplication.kt` | Package integration |
| `android/.../MainActivity.kt` | Redirect URL handling |
| `AndroidManifest.xml` | Intent filter |

Last updated on **Nov 23, 2026**