Auth on app resume
This commit is contained in:
parent
455d76f599
commit
9d2929836a
|
@ -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) {
|
||||
|
|
|
@ -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);
|
Loading…
Reference in New Issue