From dd0c6babb832772cb017171476b2629ef00ee147 Mon Sep 17 00:00:00 2001
From: eug-vs <eug-vs@keemail.me>
Date: Mon, 15 Jun 2020 17:27:11 +0300
Subject: feat: invalidate from on error

---
 src/index.tsx | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

(limited to 'src/index.tsx')

diff --git a/src/index.tsx b/src/index.tsx
index b9204b6..f28aff8 100644
--- a/src/index.tsx
+++ b/src/index.tsx
@@ -52,8 +52,8 @@ const App: React.FC = () => {
     }
   };
 
-  const logIn = (name: string, password: string) => {
-    post('/authentication', {
+  const logIn = (name: string, password: string): Promise<boolean> => {
+    return post('/authentication', {
       strategy: 'local',
       name,
       password
@@ -65,7 +65,8 @@ const App: React.FC = () => {
       localStorage.setItem('userId', user._id);
       localStorage.setItem('token', accessToken);
       navigate('profile', user._id);
-    });
+      return true;
+    }).catch(error => false);
   };
 
   const logOut = () => {
@@ -91,7 +92,7 @@ const App: React.FC = () => {
       <div className={classes.root}>
         { page.prefix === 'profile' && <ProfilePage logOut={logOut} id={page.id} navigate={navigate} /> }
         { page.prefix === 'feed' && <FeedPage navigate={navigate} /> }
-        { page.prefix === 'auth' && <AuthPage logIn={logIn} navigate={navigate} /> }
+        { page.prefix === 'auth' && <AuthPage logIn={logIn} /> }
       </div>
     </ThemeProvider>
   );
-- 
cgit v1.2.3

