This repository has been archived by the owner on Nov 26, 2017. It is now read-only.
forked from naoufal/react-native-touch-id
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TouchID.ios.js
66 lines (54 loc) · 1.37 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
61
62
63
64
65
66
/**
* @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 => {
if (error) {
return reject(createError(error.message));
}
resolve(true);
});
});
},
authenticate(reason) {
var authReason;
// Set auth reason
if (reason) {
authReason = reason;
// Set as empty string if no reason is passed
} else {
authReason = ' ';
}
return new Promise((resolve, reject) => {
NativeTouchID.authenticate(authReason, 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);
}