Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

fix session expiring issue

ammarahm-ed35384fdd8b30
diff --git a/apps/mobile/src/components/LoginDialog/index.js b/apps/mobile/src/components/LoginDialog/index.js
index dac782858..cc2319557 100644
--- a/apps/mobile/src/components/LoginDialog/index.js
+++ b/apps/mobile/src/components/LoginDialog/index.js
@@ -1,16 +1,12 @@
-import React, { useEffect, useRef, useState } from 'react';
-import {
- ScrollView,
- Text, TouchableOpacity,
- View
-} from 'react-native';
+import React, {useEffect, useRef, useState} from 'react';
+import {ScrollView, Text, TouchableOpacity, View} from 'react-native';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
-import { Button } from '../../components/Button';
+import {Button} from '../../components/Button';
import Seperator from '../../components/Seperator';
-import { useTracked } from '../../provider/index';
-import { useUserStore } from '../../provider/stores';
+import {useTracked} from '../../provider/index';
+import {useUserStore} from '../../provider/stores';
import BiometricService from '../../services/BiometricService';
-import { DDS } from '../../services/DeviceDetection';
+import {DDS} from '../../services/DeviceDetection';
import {
eSendEvent,
eSubscribeEvent,
@@ -18,25 +14,24 @@ import {
presentSheet,
ToastEvent
} from '../../services/EventManager';
-import { clearMessage, setEmailVerifyMessage } from '../../services/Message';
+import {clearMessage, setEmailVerifyMessage} from '../../services/Message';
import PremiumService from '../../services/PremiumService';
-import { hexToRGBA } from '../../utils/ColorUtils';
-import { db } from '../../utils/database';
-import {
- eOpenLoginDialog, eOpenResultDialog
-} from '../../utils/Events';
-import { openLinkInBrowser } from '../../utils/functions';
-import { MMKV } from '../../utils/mmkv';
-import { SIZE } from '../../utils/SizeUtils';
+import Sync from '../../services/Sync';
+import {hexToRGBA} from '../../utils/ColorUtils';
+import {db} from '../../utils/database';
+import {eOpenLoginDialog, eOpenResultDialog} from '../../utils/Events';
+import {openLinkInBrowser} from '../../utils/functions';
+import {MMKV} from '../../utils/mmkv';
+import {SIZE} from '../../utils/SizeUtils';
import Storage from '../../utils/storage';
-import { sleep } from '../../utils/TimeUtils';
+import {sleep} from '../../utils/TimeUtils';
import ActionSheetWrapper from '../ActionSheetComponent/ActionSheetWrapper';
import BaseDialog from '../Dialog/base-dialog';
import DialogButtons from '../Dialog/dialog-buttons';
import DialogContainer from '../Dialog/dialog-container';
import DialogHeader from '../Dialog/dialog-header';
import Input from '../Input';
-import { Header } from '../SimpleList/header';
+import {Header} from '../SimpleList/header';
import Paragraph from '../Typography/Paragraph';
const MODES = {
@@ -182,13 +177,13 @@ const LoginDialog = () => {
setMode(mode ? mode : MODES.login);
if (mode === MODES.sessionExpired) {
try {
- // let res = await db.user.tokenManager.getToken();
- // if (!res) throw new Error('no token found');
- // if (db.user.tokenManager._isTokenExpired(res))
- // throw new Error('token expired');
- // if (!(await Sync.run())) throw new Error('e');
- // await MMKV.removeItem('loginSessionHasExpired');
- throw new Error("Error");
+ console.log('REQUESTING NEW TOKEN');
+ let res = await db.user.tokenManager.getToken();
+ if (!res) throw new Error('no token found');
+ if (db.user.tokenManager._isTokenExpired(res))
+ throw new Error('token expired');
+ if (!(await Sync.run())) throw new Error('e');
+ await MMKV.removeItem('loginSessionHasExpired');
return;
} catch (e) {
console.log(e);
@@ -248,7 +243,7 @@ const LoginDialog = () => {
close();
await MMKV.removeItem('loginSessionHasExpired');
eSendEvent('userLoggedIn', true);
- console.log("PRESENTING SHEET");
+ console.log('PRESENTING SHEET');
await sleep(500);
presentSheet({
title: 'Syncing your data',
@@ -735,7 +730,7 @@ const LoginDialog = () => {
height={50}
/>
- {current.buttonAlt && MODES.sessionExpired !== mode && (
+ {current.buttonAlt && MODES.sessionExpired !== mode && (
<Button
title={current.buttonAlt}
onPress={current.buttonAltFunc}
diff --git a/apps/mobile/src/utils/useAppEvents.js b/apps/mobile/src/utils/useAppEvents.js
index ce7afdca7..54b295af7 100644
--- a/apps/mobile/src/utils/useAppEvents.js
+++ b/apps/mobile/src/utils/useAppEvents.js
@@ -463,7 +463,6 @@ export const useAppEvents = () => {
}
}
refValues.current.prevState = 'active';
- console.log(state,"SETTING VALUE");
await reconnectSSE();
await checkIntentState();
if (getWebviewInit()) {