Auth on app resume

This commit is contained in:
Diego Mello 2020-04-14 09:25:17 -03:00
parent 455d76f599
commit 9d2929836a
2 changed files with 51 additions and 1 deletions

View File

@ -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) {

View File

@ -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);