forked from naoufal/react-native-touch-id
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TouchID.android.js
53 lines (46 loc) · 1.58 KB
/
TouchID.android.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
import { NativeModules, processColor } from 'react-native';
const NativeTouchID = NativeModules.FingerprintAuth;
// Android provides more flexibility than iOS for handling the Fingerprint. Currently the config object accepts customizable title or color. Otherwise it defaults to this constant
export default {
isSupported() {
return new Promise((resolve, reject) => {
NativeTouchID.isSupported(
error => {
return reject(typeof error == 'String' ? createError(error, error) : createError(error));
},
success => {
return resolve(true);
}
);
});
},
authenticate(reason, config) {
var DEFAULT_CONFIG = { title: 'Authentication Required', color: '#1306ff' };
var authReason = reason ? reason : ' ';
var authConfig = Object.assign({}, DEFAULT_CONFIG, config);
var color = processColor(authConfig.color);
authConfig.color = color;
return new Promise((resolve, reject) => {
NativeTouchID.authenticate(
authReason,
authConfig,
error => {
return reject(typeof error == 'String' ? createError(error, error) : createError(error));
},
success => {
return 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) {
return new TouchIDError('Touch ID Error', error);
}