-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[FIX] Differ to Last Session Authenticated #3667
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
Changes from 2 commits
9a283fe
88cab2c
0b71ab8
3db4e29
acd8a2d
dac4194
6d4c8ac
080e7bc
bfd3589
6c54776
cc4a573
c1d190c
e25d5fd
1e01a65
330f8f5
133fca8
787060f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -169,6 +169,17 @@ const RocketChat = { | |
| message: I18n.t('Not_RC_Server', { contact: I18n.t('Contact_your_server_admin') }) | ||
| }; | ||
| }, | ||
| async getServerTimeSync(server) { | ||
| try { | ||
| const response = await RNFetchBlob.fetch('GET', `${server}/_timesync`); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This request takes 1600ms on https://mobile.rocket.chat, so we should be careful on the impact. before.mp4after.mp4A good solution for this is to move |
||
| if (response?.data) { | ||
| return parseInt(response.data); | ||
| } | ||
| return null; | ||
| } catch { | ||
| return null; | ||
| } | ||
| }, | ||
| stopListener(listener) { | ||
| return listener && listener.stop(); | ||
| }, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,12 @@ | ||
| import * as LocalAuthentication from 'expo-local-authentication'; | ||
| import moment from 'moment'; | ||
| import RNBootSplash from 'react-native-bootsplash'; | ||
| import AsyncStorage from '@react-native-community/async-storage'; | ||
| import { sha256 } from 'js-sha256'; | ||
|
|
||
| import UserPreferences from '../lib/userPreferences'; | ||
| import store from '../lib/createStore'; | ||
| import database from '../lib/database'; | ||
| import RocketChat from '../lib/rocketchat'; | ||
| import { | ||
| ATTEMPTS_KEY, | ||
| CHANGE_PASSCODE_EMITTER, | ||
|
|
@@ -21,6 +21,8 @@ import EventEmitter from './events'; | |
| import { isIOS } from './deviceInfo'; | ||
|
|
||
| export const saveLastLocalAuthenticationSession = async (server: string, serverRecord?: TServerModel): Promise<void> => { | ||
| const timesync: number = (await RocketChat.getServerTimeSync(server)) ?? 0; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's awkward to call this request again here. |
||
|
|
||
| const serversDB = database.servers; | ||
| const serversCollection = serversDB.get('servers'); | ||
| await serversDB.write(async () => { | ||
|
|
@@ -29,7 +31,7 @@ export const saveLastLocalAuthenticationSession = async (server: string, serverR | |
| serverRecord = (await serversCollection.find(server)) as TServerModel; | ||
| } | ||
| await serverRecord.update(record => { | ||
| record.lastLocalAuthenticatedSession = new Date(); | ||
| record.lastLocalAuthenticatedSession = new Date(timesync); | ||
| }); | ||
| } catch (e) { | ||
| // Do nothing | ||
|
|
@@ -128,11 +130,19 @@ export const localAuthenticate = async (server: string): Promise<void> => { | |
|
|
||
| // `checkHasPasscode` results newPasscode = true if a passcode has been set | ||
| if (!result?.newPasscode) { | ||
| // Get time from server | ||
| const timesync: number | null = await RocketChat.getServerTimeSync(server); | ||
|
|
||
| // diff to last authenticated session | ||
| const diffToLastSession = moment().diff(serverRecord?.lastLocalAuthenticatedSession, 'seconds'); | ||
| let diffToLastSession = -1; | ||
| if (timesync) { | ||
| diffToLastSession = Math.round((timesync - serverRecord?.lastLocalAuthenticatedSession.getTime()) / 1000); | ||
| } | ||
|
|
||
| // if last authenticated session is older than configured auto lock time, authentication is required | ||
| if (diffToLastSession >= serverRecord.autoLockTime!) { | ||
| // check if diffToLastSession is negative | ||
| // check if timesync is truly, if isn't will show always the modal | ||
| if (!timesync || diffToLastSession < 0 || (serverRecord?.autoLockTime && diffToLastSession >= serverRecord.autoLockTime)) { | ||
| // set isLocalAuthenticated to false | ||
| store.dispatch(setLocalAuthenticated(false)); | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.