Auto lock option label
This commit is contained in:
parent
fa93c26744
commit
36b39ffaf5
|
@ -2,6 +2,7 @@ import * as LocalAuthentication from 'expo-local-authentication';
|
|||
import moment from 'moment';
|
||||
|
||||
import database from '../lib/database';
|
||||
import { isIOS } from './deviceInfo';
|
||||
|
||||
export const saveLastLocalAuthenticationSession = async(server) => {
|
||||
console.log('saveLastLocalAuthenticationSession -> server', server);
|
||||
|
@ -32,10 +33,13 @@ export const localAuthenticate = async(server) => {
|
|||
return Promise.reject();
|
||||
}
|
||||
|
||||
console.log('localAuthenticate -> serverRecord', serverRecord);
|
||||
if (serverRecord?.autoLock) {
|
||||
const diffToLastSession = moment().diff(serverRecord?.lastLocalAuthenticatedSession, 'seconds');
|
||||
console.log('localAuthenticate -> diffToLastSession', diffToLastSession);
|
||||
if (diffToLastSession >= serverRecord?.autoLockTime) {
|
||||
const supported = await LocalAuthentication.supportedAuthenticationTypesAsync();
|
||||
console.log('localAuthenticate -> supported', supported);
|
||||
const authResult = await LocalAuthentication.authenticateAsync();
|
||||
if (authResult?.success) {
|
||||
await saveLastLocalAuthenticationSession(server);
|
||||
|
@ -47,3 +51,19 @@ export const localAuthenticate = async(server) => {
|
|||
}
|
||||
return Promise.resolve(true);
|
||||
};
|
||||
|
||||
export const supportedAuthenticationLabel = async() => {
|
||||
const supported = await LocalAuthentication.supportedAuthenticationTypesAsync();
|
||||
console.log('supportedAuthenticationLabel -> supported', supported);
|
||||
|
||||
const enrolled = await LocalAuthentication.isEnrolledAsync();
|
||||
console.log('supportedAuthenticationLabel -> enrolled', enrolled);
|
||||
|
||||
if (supported.includes(LocalAuthentication.AuthenticationType.FACIAL_RECOGNITION)) {
|
||||
return isIOS ? 'FaceID' : 'facial recognition';
|
||||
}
|
||||
if (supported.includes(LocalAuthentication.AuthenticationType.FINGERPRINT)) {
|
||||
return isIOS ? 'TouchID' : 'fingerprint';
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
|
|
@ -16,11 +16,12 @@ import Separator from '../containers/Separator';
|
|||
import ListItem from '../containers/ListItem';
|
||||
import { CustomIcon } from '../lib/Icons';
|
||||
import database from '../lib/database';
|
||||
import { supportedAuthenticationLabel } from '../utils/localAuthentication';
|
||||
|
||||
const DEFAULT_AUTO_LOCK = [
|
||||
{
|
||||
title: 'After 1 minute',
|
||||
value: 60
|
||||
value: 0
|
||||
},
|
||||
{
|
||||
title: 'After 5 minutes',
|
||||
|
@ -80,7 +81,8 @@ class ScreenLockConfigView extends React.Component {
|
|||
this.state = {
|
||||
autoLock: false,
|
||||
autoLockTime: null,
|
||||
supported: []
|
||||
supported: [],
|
||||
autoLockLabel: ''
|
||||
};
|
||||
this.init();
|
||||
}
|
||||
|
@ -95,6 +97,9 @@ class ScreenLockConfigView extends React.Component {
|
|||
} catch (error) {
|
||||
// TODO: raise error in case server wasn't found and pop?
|
||||
}
|
||||
|
||||
const autoLockLabel = await supportedAuthenticationLabel();
|
||||
this.setState({ autoLockLabel });
|
||||
}
|
||||
|
||||
save = async() => {
|
||||
|
@ -175,7 +180,7 @@ class ScreenLockConfigView extends React.Component {
|
|||
}
|
||||
|
||||
render() {
|
||||
const { autoLock, supported } = this.state;
|
||||
const { autoLock, supported, autoLockLabel } = this.state;
|
||||
const { theme } = this.props;
|
||||
return (
|
||||
<SafeAreaView
|
||||
|
@ -190,7 +195,7 @@ class ScreenLockConfigView extends React.Component {
|
|||
>
|
||||
<Separator theme={theme} />
|
||||
<ListItem
|
||||
title='Unlock with METHODHERE'
|
||||
title={`Unlock with ${ autoLockLabel }`}
|
||||
right={() => this.renderSwitch()}
|
||||
theme={theme}
|
||||
/>
|
||||
|
|
Loading…
Reference in New Issue