Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Screen Lock #2177

Merged
merged 6 commits into from
Jun 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/actions/actionsTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
7 changes: 7 additions & 0 deletions app/actions/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,10 @@ export function setPreference(preference) {
preference
};
}

export function setLocalAuthenticated(isLocalAuthenticated) {
return {
type: types.LOGIN.SET_LOCAL_AUTHENTICATED,
isLocalAuthenticated
};
}
6 changes: 6 additions & 0 deletions app/reducers/login.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as types from '../actions/actionsTypes';

const initialState = {
isLocalAuthenticated: true,
isAuthenticated: false,
isFetching: false,
user: {},
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 4 additions & 0 deletions app/sagas/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions app/utils/localAuthentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ 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';
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;
Expand Down Expand Up @@ -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();

Expand All @@ -123,6 +128,9 @@ export const localAuthenticate = async(server) => {

// Authenticate
await openModal(hasBiometry);

// set isLocalAuthenticated to true
store.dispatch(setLocalAuthenticated(true));
}
}

Expand Down