A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
fix login flow
ammarahm-ed63b805364158
diff --git a/apps/mobile/AppRootEvents.js b/apps/mobile/AppRootEvents.jsindex d727aaa7d..0397ded3a 100644--- a/apps/mobile/AppRootEvents.js+++ b/apps/mobile/AppRootEvents.js@@ -10,7 +10,12 @@ import {useTracked} from './src/provider';import {Actions} from './src/provider/Actions';import Backup from './src/services/Backup';import BiometricService from './src/services/BiometricService';-import {eSendEvent, ToastEvent} from './src/services/EventManager';+import {+ eSendEvent,+ eSubscribeEvent,+ eUnSubscribeEvent,+ ToastEvent,+} from './src/services/EventManager';import {clearMessage,setEmailVerifyMessage,@@ -71,7 +76,7 @@ async function checkIntentState() {async function reconnectSSE(connection) {if (!isUserReady) {- console.log("user is not ready")+ console.log('user is not ready');return;}let state = connection;@@ -164,8 +169,12 @@ export const AppRootEvents = React.memo(EV.subscribe(EVENTS.userCheckStatus, PremiumService.onUserStatusCheck);EV.subscribe(EVENTS.userSubscriptionUpdated, onAccountStatusChange);EV.subscribe(EVENTS.noteRemoved, onNoteRemoved);-+ eSubscribeEvent('userLoggedIn', setCurrentUser);+ removeInternetStateListener = NetInfo.addEventListener(+ onInternetStateChanged,+ );return () => {+ eUnSubscribeEvent('userLoggedIn', setCurrentUser);EV.unsubscribe(EVENTS.appRefreshRequested, onSyncComplete);EV.unsubscribe(EVENTS.databaseSyncRequested, partialSync);EV.unsubscribe(EVENTS.userLoggedOut, onLogout);@@ -184,7 +193,6 @@ export const AppRootEvents = React.memo(const onNoteRemoved = async (id) => {try {- console.log('removing note');await db.notes.remove(id);Navigation.setRoutesToUpdate([Navigation.routeNames.Favorites,@@ -352,7 +360,7 @@ export const AppRootEvents = React.memo(}};- const setCurrentUser = async () => {+ const setCurrentUser = async (login) => {try {let user = await db.user.getUser();if (user) {@@ -364,9 +372,6 @@ export const AppRootEvents = React.memo(setEmailVerifyMessage(dispatch);return;}- removeInternetStateListener = NetInfo.addEventListener(- onInternetStateChanged,- );await Sync.run();user = await db.user.fetchUser(true);dispatch({type: Actions.USER, user: user});@@ -385,8 +390,10 @@ export const AppRootEvents = React.memo(}} finally {isUserReady = true;+ if (login) {+ eSendEvent(eCloseProgressDialog);+ }}-};const onSuccessfulSubscription = async (subscription) => {@@ -399,7 +406,6 @@ export const AppRootEvents = React.memo(};const onSubscriptionError = async (error) => {- console.log('IAP ERROR', error);ToastEvent.show({heading: 'Failed to subscribe',type: 'error',diff --git a/apps/mobile/src/components/LoginDialog/index.js b/apps/mobile/src/components/LoginDialog/index.jsindex dc082c760..7e9a2866e 100644--- a/apps/mobile/src/components/LoginDialog/index.js+++ b/apps/mobile/src/components/LoginDialog/index.js@@ -16,6 +16,7 @@ import {} from '../../services/EventManager';import {clearMessage, setEmailVerifyMessage} from '../../services/Message';import PremiumService from '../../services/PremiumService';+import Sync from '../../services/Sync';import {getElevation} from '../../utils';import {db} from '../../utils/DB';import {@@ -183,7 +184,7 @@ const LoginDialog = () => {try {await db.user.login(email.toLowerCase(), password, true);user = await db.user.getUser();- if (!user) throw new Error('Email or passoword incorrect!');+ if (!user) throw new Error('Email or password incorrect!');setStatus('Syncing Your Data');PremiumService.setPremiumStatus();dispatch({type: Actions.USER, user: user});@@ -196,33 +197,21 @@ const LoginDialog = () => {});close();await sleep(300);+ eSendEvent('userLoggedIn', true);eSendEvent(eOpenProgressDialog, {title: 'Syncing your data',paragraph: 'Please wait while we sync all your data.',noProgress: false,});- await db.sync();- dispatch({type: Actions.LAST_SYNC, lastSync: await db.lastSynced()});- dispatch({type: Actions.ALL});- eSendEvent(refreshNotesPage);- eSendEvent(eCloseProgressDialog);} catch (e) {setLoading(false);setStatus(null);- if (user && !user.isEmailConfirmed) {- close();- setEmailVerifyMessage(dispatch);- await sleep(500);- console.log('showing verify email dialog');- PremiumService.showVerifyEmailDialog();- } else {- ToastEvent.show({- heading: user ? 'Failed to sync' : 'Login failed',- message: e.message,- type: 'error',- context: 'local',- });- }+ ToastEvent.show({+ heading: user ? 'Failed to sync' : 'Login failed',+ message: e.message,+ type: 'error',+ context: 'local',+ });}};