forked from naoufal/react-native-touch-id
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TouchID.ios.js
60 lines (49 loc) · 1.39 KB
/
TouchID.ios.js
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
/**
* @providesModule TouchID
* @flow
*/
'use strict';
import { NativeModules } from 'react-native';
const NativeTouchID = NativeModules.TouchID;
const ERRORS = require('./data/errors');
/**
* High-level docs for the TouchID iOS API can be written here.
*/
export default {
isSupported() {
return new Promise((resolve, reject) => {
NativeTouchID.isSupported((error, biometryType) => {
if (error) {
return reject(createError(error.message));
}
resolve(biometryType);
});
});
},
authenticate(reason, config) {
const DEFAULT_CONFIG = { fallbackLabel: null };
const authReason = reason ? reason : ' ';
const authConfig = config ? config : DEFAULT_CONFIG;
return new Promise((resolve, reject) => {
NativeTouchID.authenticate(authReason, authConfig, error => {
// Return error if rejected
if (error) {
return reject(createError(error.message));
}
resolve(true);
});
});
}
};
function TouchIDError(name, details) {
this.name = name || 'TouchIDError';
this.message = details.message || 'Touch ID Error';
this.details = details || {};
}
TouchIDError.prototype = Object.create(Error.prototype);
TouchIDError.prototype.constructor = TouchIDError;
function createError(error) {
let details = ERRORS[error];
details.name = error;
return new TouchIDError(error, details);
}