@grupalia/react-native-face-liveness
v0.1.2
Published
React Native (Expo) view for AWS Rekognition Face Liveness, with session credentials passed from JS
Readme
@grupalia/react-native-face-liveness
React Native (Expo) view for AWS Rekognition Face Liveness, with session credentials passed from JS.
It wraps the Amplify UI liveness detectors (amplify-ui-swift-liveness on iOS,
com.amplifyframework.ui:liveness on Android). The app never holds long-lived AWS credentials:
the backend creates the liveness session, mints temporary STS credentials that can only stream
to it, and hands both to the view.
Requirements
- Expo SDK 54 or later with a development build (Expo Go is not supported)
- iOS 15.1+, Android minSdk 24+
Install
yarn add @grupalia/react-native-face-livenessAdd the config plugin to app.json (or app.config.ts):
{
"expo": {
"plugins": ["@grupalia/react-native-face-liveness"]
}
}Run npx expo prebuild after installing and after any plugin change. The plugin:
- enables core library desugaring in the Android app (required by the Amplify liveness library)
- writes the Spanish liveness strings to Android
strings.xmland to an iOSLocalizable.stringsadded to the app target
The camera permission is declared by the library on Android. On iOS the app must provide
NSCameraUsageDescription.
Usage
import { FaceLivenessDetectorView } from '@grupalia/react-native-face-liveness';
<FaceLivenessDetectorView
sessionId={session.sessionId}
region="us-east-1"
credentials={session.credentials}
disableStartView
onComplete={({ nativeEvent }) => submitSession(nativeEvent.sessionId)}
onError={({ nativeEvent }) => showError(nativeEvent.message)}
/>Props
| Prop | Type | Notes |
|---|---|---|
| sessionId | string | Rekognition liveness session id, created by the backend |
| region | string | AWS region of the session |
| credentials | LivenessCredentials | Temporary credentials allowed to stream to the session |
| disableStartView | boolean | Skips the Amplify intro screen and opens the camera on the oval |
| style | StyleProp<ViewStyle> | Defaults to flex: 1, so the view fills its parent; anything passed is merged on top. The view has no intrinsic size, so its parent must have one |
| onComplete | ({ nativeEvent: { sessionId } }) => void | The video was streamed. The verdict is read by the backend, never on the device |
| onError | ({ nativeEvent: { sessionId, message, recoverySuggestion, cause } }) => void | Camera, network, timeout or user cancellation |
LivenessCredentials is { accessKeyId, secretAccessKey, sessionToken, expiration }, with
expiration in epoch seconds.
The detector starts once sessionId, region and credentials are all set, and runs once per
sessionId. To retry, create a new session and pass its id, or remount the view.
iOS builds
The Amplify Swift packages ship an SPM build plugin (SmithyCodeGeneratorPlugin). Xcode asks to
trust it on the first local build; accept it once, or run:
defaults write com.apple.dt.Xcode IDESkipPackagePluginFingerprintValidatation -bool YES(The misspelling is Apple's.) On EAS, if a build stops at "Planning build", add the same command
as an eas-build-pre-install hook.
Development
yarn install
yarn typecheck
yarn lint
yarn buildTry changes in an app before publishing with yalc:
yarn publish-local here, then npx yalc add @grupalia/react-native-face-liveness in the app and
rebuild the native project.
Release
Bump the version with yarn bump-patch-version (or -minor-, -major-) and merge to main. CI
publishes to npm when the version changes and creates the v<version> GitHub release.
