-
Notifications
You must be signed in to change notification settings - Fork 53
/
PasscodeAuth.ios.js
59 lines (48 loc) · 1.1 KB
/
PasscodeAuth.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
/**
* @providesModule Passcode
* @flow
*/
'use strict';
var React = require('react-native');
var {
NativeModules
} = React;
var NativePasscodeAuth = NativeModules.PasscodeAuth;
/**
* High-level docs for the Passcode iOS API can be written here.
*/
var PasscodeAuth = {
isSupported() {
return new Promise(function(resolve, reject) {
NativePasscodeAuth.isSupported(function(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(function(resolve, reject) {
NativePasscodeAuth.authenticate(authReason, function(error) {
// Return error if rejected
if (error) {
return reject(createError(error.message));
}
resolve(true);
});
});
}
};
function createError(error) {
return new Error(error);
}
module.exports = PasscodeAuth;