From 9d2929836a148260af0a35240cb7191971bdc93a Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Tue, 14 Apr 2020 09:25:17 -0300 Subject: [PATCH] Auth on app resume --- app/sagas/state.js | 8 +++- ...enhancer-react-native-appstate+0.3.1.patch | 44 +++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 patches/redux-enhancer-react-native-appstate+0.3.1.patch diff --git a/app/sagas/state.js b/app/sagas/state.js index 6e3d33728..2ac1ae431 100644 --- a/app/sagas/state.js +++ b/app/sagas/state.js @@ -1,9 +1,11 @@ -import { takeLatest, select } from 'redux-saga/effects'; +import { takeLatest, select, put } from 'redux-saga/effects'; import { FOREGROUND, BACKGROUND } from 'redux-enhancer-react-native-appstate'; +import * as LocalAuthentication from 'expo-local-authentication'; import RocketChat from '../lib/rocketchat'; import { setBadgeCount } from '../notifications/push'; import log from '../utils/log'; +import * as actions from '../actions'; const appHasComeBackToForeground = function* appHasComeBackToForeground() { const appRoot = yield select(state => state.app.root); @@ -15,6 +17,10 @@ const appHasComeBackToForeground = function* appHasComeBackToForeground() { return; } try { + const authResult = yield LocalAuthentication.authenticateAsync(); + if (!authResult?.success) { + yield put(actions.appStart('locked')); + } setBadgeCount(); return yield RocketChat.setUserPresenceOnline(); } catch (e) { diff --git a/patches/redux-enhancer-react-native-appstate+0.3.1.patch b/patches/redux-enhancer-react-native-appstate+0.3.1.patch new file mode 100644 index 000000000..f756408fc --- /dev/null +++ b/patches/redux-enhancer-react-native-appstate+0.3.1.patch @@ -0,0 +1,44 @@ +diff --git a/node_modules/redux-enhancer-react-native-appstate/index.js b/node_modules/redux-enhancer-react-native-appstate/index.js +index 769e39c..db9e993 100644 +--- a/node_modules/redux-enhancer-react-native-appstate/index.js ++++ b/node_modules/redux-enhancer-react-native-appstate/index.js +@@ -10,22 +10,25 @@ export default () => (createStore) => (...args) => { + let currentState = ''; + + const handleAppStateChange = (nextAppState) => { +- if (currentState !== nextAppState) { +- let type; +- if (nextAppState === 'active') { +- type = FOREGROUND; +- } else if (nextAppState === 'background') { +- type = BACKGROUND; +- } else if (nextAppState === 'inactive') { +- type = INACTIVE; +- } +- if (type) { +- store.dispatch({ +- type, +- }); ++ if (nextAppState !== 'inactive') { ++ if (currentState !== nextAppState) { ++ let type; ++ if (nextAppState === 'active') { ++ type = FOREGROUND; ++ } else if (nextAppState === 'background') { ++ type = BACKGROUND; ++ } ++ // else if (nextAppState === 'inactive') { ++ // type = INACTIVE; ++ // } ++ if (type) { ++ store.dispatch({ ++ type, ++ }); ++ } + } ++ currentState = nextAppState; + } +- currentState = nextAppState; + }; + + AppState.addEventListener('change', handleAppStateChange);