From ecacfa5c06fac686f26c93186cd2dad3e0faac16 Mon Sep 17 00:00:00 2001 From: ammarahm-ed Date: Mon, 4 Jan 2021 14:52:27 +0500 Subject: [PATCH] fix login flow --- .../src/components/LoginDialog/index.js | 30 +++++-------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/apps/mobile/src/components/LoginDialog/index.js b/apps/mobile/src/components/LoginDialog/index.js index 7d1dad692..e2d28bbfc 100644 --- a/apps/mobile/src/components/LoginDialog/index.js +++ b/apps/mobile/src/components/LoginDialog/index.js @@ -178,41 +178,27 @@ const LoginDialog = () => { try { await db.user.login(email.toLowerCase(), password, true); - } catch (e) { - console.log(e); - ToastEvent.show(e.message, 'error', 'local'); - setLoading(false); - setStatus(null); - return; - } - - try { let user = await db.user.getUser(); + console.log(user); if (!user) throw new Error('Email or passoword incorrect!'); setStatus('Syncing Data'); dispatch({type: Actions.USER, user: user}); - db.sync() - .catch((e) => { - console.log(e); - }) - .finally(async () => { - dispatch({type: Actions.LAST_SYNC, lastSync: await db.lastSynced()}); - dispatch({type: Actions.ALL}); - eSendEvent(refreshNotesPage); - }); clearMessage(dispatch); if (!user.isEmailConfirmed) { setEmailVerifyMessage(dispatch); PremiumService.showVerifyEmailDialog(); } - close(); ToastEvent.show(`Logged in as ${user.email}`, 'success', 'global'); + await db.sync(); + dispatch({type: Actions.LAST_SYNC, lastSync: await db.lastSynced()}); + dispatch({type: Actions.ALL}); + eSendEvent(refreshNotesPage); + setLoading(false); + close(); } catch (e) { - console.warn(e); + setLoading(false); setStatus(null); ToastEvent.show(e.message, 'error', 'local'); - } finally { - setLoading(false); } };