UNPKG

1.02 kBJavaScriptView Raw
1// @flow
2
3import invariant from 'invariant';
4import { NativeModules, Platform } from 'react-native';
5
6const { ExponentFingerprint } = NativeModules;
7
8type FingerprintAuthenticationResult = { success: true } | { success: false, error: string };
9
10export function hasHardwareAsync(): Promise<boolean> {
11 return ExponentFingerprint.hasHardwareAsync();
12}
13
14export function isEnrolledAsync(): Promise<boolean> {
15 return ExponentFingerprint.isEnrolledAsync();
16}
17
18export function authenticateAsync(
19 promptMessageIOS?: string = 'Authenticate'
20): Promise<FingerprintAuthenticationResult> {
21 if (Platform.OS === 'ios') {
22 invariant(
23 typeof promptMessageIOS === 'string' && promptMessageIOS.length,
24 'Fingerprint.authenticateAsync must be called with a non-empty string on iOS'
25 );
26 return ExponentFingerprint.authenticateAsync(promptMessageIOS);
27 } else {
28 return ExponentFingerprint.authenticateAsync();
29 }
30}
31
32export function cancelAuthenticate(): void {
33 ExponentFingerprint.cancelAuthenticate();
34}