forked from tradle/react-native-local-auth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LocalAuth.ios.js
56 lines (48 loc) · 1.34 KB
/
LocalAuth.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
/**
* Mostly a copy of https://github.com/naoufal/react-native-touch-id
* @providesModule LocalAuth
* @flow
*/
'use strict'
import { NativeModules } from 'react-native'
import { createError } from './error'
import PasscodeStatus from 'react-native-passcode-status'
let NativeLocalAuth = NativeModules.RNLocalAuth
let LocalAuth = {
hasTouchID() {
return new Promise(function(resolve, reject) {
NativeLocalAuth.hasTouchID(function(error) {
if (error) {
return reject(createError(error.message))
}
resolve()
})
})
},
isDeviceSecure() {
if (!PasscodeStatus.supported) {
return Promise.reject(new Error('unable to determine'))
}
return new Promise((resolve, reject) => {
PasscodeStatus.get(function (err, status) {
if (err) return reject(new Error(err))
if (status === 'unknown') return reject(new Error('unable to determine'))
resolve(status === 'enabled')
})
})
},
authenticate(opts) {
return new Promise(function(resolve, reject) {
NativeLocalAuth.authenticate(
opts.reason || '',
!!opts.fallbackToPasscode,
!!opts.suppressEnterPassword,
function (error) {
if (error) reject(createError(error.message))
else resolve()
}
)
})
}
}
module.exports = LocalAuth