[FIX] Screen Lock (#2177)

* [FIX] Screen Lock

* improve variable name

Co-authored-by: Djorkaeff Alexandre <djorkaeff.unb@gmail.com>
This commit is contained in:
Diego Mello 2020-06-09 17:19:54 -03:00 committed by GitHub
parent caf1ef2cfe
commit 2cc599cc5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 1 deletions

View File

@ -12,7 +12,8 @@ function createRequestTypes(base, types = defaultTypes) {
export const LOGIN = createRequestTypes('LOGIN', [
...defaultTypes,
'SET_SERVICES',
'SET_PREFERENCE'
'SET_PREFERENCE',
'SET_LOCAL_AUTHENTICATED'
]);
export const SHARE = createRequestTypes('SHARE', [
'SELECT_SERVER',

View File

@ -49,3 +49,10 @@ export function setPreference(preference) {
preference
};
}
export function setLocalAuthenticated(isLocalAuthenticated) {
return {
type: types.LOGIN.SET_LOCAL_AUTHENTICATED,
isLocalAuthenticated
};
}

View File

@ -1,6 +1,7 @@
import * as types from '../actions/actionsTypes';
const initialState = {
isLocalAuthenticated: true,
isAuthenticated: false,
isFetching: false,
user: {},
@ -68,6 +69,11 @@ export default function login(state = initialState, action) {
}
}
};
case types.LOGIN.SET_LOCAL_AUTHENTICATED:
return {
...state,
isLocalAuthenticated: action.isLocalAuthenticated
};
default:
return state;
}

View File

@ -34,6 +34,10 @@ const appHasComeBackToBackground = function* appHasComeBackToBackground() {
if (!auth) {
return;
}
const localAuthenticated = yield select(state => state.login.isLocalAuthenticated);
if (!localAuthenticated) {
return;
}
try {
const server = yield select(state => state.server.server);
yield saveLastLocalAuthenticationSession(server);

View File

@ -5,6 +5,7 @@ import AsyncStorage from '@react-native-community/async-storage';
import RNUserDefaults from 'rn-user-defaults';
import { sha256 } from 'js-sha256';
import store from '../lib/createStore';
import database from '../lib/database';
import { isIOS } from './deviceInfo';
import EventEmitter from './events';
@ -12,6 +13,7 @@ import {
LOCAL_AUTHENTICATE_EMITTER, LOCKED_OUT_TIMER_KEY, ATTEMPTS_KEY, PASSCODE_KEY, CHANGE_PASSCODE_EMITTER
} from '../constants/localAuthentication';
import I18n from '../i18n';
import { setLocalAuthenticated } from '../actions/login';
export const saveLastLocalAuthenticationSession = async(server, serverRecord) => {
const serversDB = database.servers;
@ -100,6 +102,9 @@ export const localAuthenticate = async(server) => {
// if screen lock is enabled
if (serverRecord?.autoLock) {
// set isLocalAuthenticated to false
store.dispatch(setLocalAuthenticated(false));
// Make sure splash screen has been hidden
RNBootSplash.hide();
@ -123,6 +128,9 @@ export const localAuthenticate = async(server) => {
// Authenticate
await openModal(hasBiometry);
// set isLocalAuthenticated to true
store.dispatch(setLocalAuthenticated(true));
}
}