From 2cc599cc5e6299f71cd87aa91b30bc1ba7d715bf Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Tue, 9 Jun 2020 17:19:54 -0300 Subject: [PATCH] [FIX] Screen Lock (#2177) * [FIX] Screen Lock * improve variable name Co-authored-by: Djorkaeff Alexandre --- app/actions/actionsTypes.js | 3 ++- app/actions/login.js | 7 +++++++ app/reducers/login.js | 6 ++++++ app/sagas/state.js | 4 ++++ app/utils/localAuthentication.js | 8 ++++++++ 5 files changed, 27 insertions(+), 1 deletion(-) diff --git a/app/actions/actionsTypes.js b/app/actions/actionsTypes.js index 69b3f916..9505ae37 100644 --- a/app/actions/actionsTypes.js +++ b/app/actions/actionsTypes.js @@ -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', diff --git a/app/actions/login.js b/app/actions/login.js index 999de3e0..daf13d3b 100644 --- a/app/actions/login.js +++ b/app/actions/login.js @@ -49,3 +49,10 @@ export function setPreference(preference) { preference }; } + +export function setLocalAuthenticated(isLocalAuthenticated) { + return { + type: types.LOGIN.SET_LOCAL_AUTHENTICATED, + isLocalAuthenticated + }; +} diff --git a/app/reducers/login.js b/app/reducers/login.js index 11efc105..664718c4 100644 --- a/app/reducers/login.js +++ b/app/reducers/login.js @@ -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; } diff --git a/app/sagas/state.js b/app/sagas/state.js index 3c4d63e3..727bc6af 100644 --- a/app/sagas/state.js +++ b/app/sagas/state.js @@ -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); diff --git a/app/utils/localAuthentication.js b/app/utils/localAuthentication.js index 52a0fc4a..37c03fe3 100644 --- a/app/utils/localAuthentication.js +++ b/app/utils/localAuthentication.js @@ -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)); } }