This repository has been archived by the owner on Jun 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
72 lines (60 loc) · 2.14 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import {NativeModules} from 'react-native';
const {ReactNativeBiometricAuth: bridge} = NativeModules;
/**
* Type alias for possible biometry types
*/
export type BiometryType = 'TouchID' | 'FaceID' | 'Biometrics';
interface IsSensorAvailableResult {
available: boolean
biometryType?: BiometryType
error?: string
}
interface SimplePromptOptions {
promptMessage: string
cancelButtonText?: string
}
interface SimplePromptOptionAndroid extends SimplePromptOptions {
isDeviceAuthEnabled: boolean
}
interface SimplePromptOptionIOS extends SimplePromptOptions {
fallbackText?: string
}
interface SimplePromptResult {
success: boolean
error?: string
}
module ReactNativeBiometricAuth {
/**
* Enum for touch id sensor type
*/
export const TouchID = 'TouchID';
/**
* Enum for face id sensor type
*/
export const FaceID = 'FaceID';
/**
* Enum for generic biometrics (this is the only value available on android)
*/
export const Biometrics = 'Biometrics';
/**
* Returns promise that resolves to an object with object.biometryType = Biometrics | TouchID | FaceID
* @returns {Promise<Object>} Promise that resolves to an object with details about biometrics available
*/
export function isSensorAvailable(): Promise<IsSensorAvailableResult> {
return bridge.isSensorAvailable();
}
/**
* Prompts user with biometrics dialog using the passed in prompt message and
* returns promise that resolves to an object with object.success = true if the user passes,
* object.success = false if the user cancels, and rejects if anything fails
* @param {Object} simplePromptOption
* @returns {Promise<Object>} Promise that resolves an object with details about the biometrics result
*/
export function simplePrompt(simplePromptOption: SimplePromptOptionAndroid | SimplePromptOptionIOS): Promise<SimplePromptResult> {
if (!simplePromptOption.cancelButtonText) {
simplePromptOption.cancelButtonText = 'Cancel';
}
return bridge.simplePrompt(simplePromptOption);
}
}
export default ReactNativeBiometricAuth;