From 3cff0821a8989afca1effb5420d8d0d55d513dbf Mon Sep 17 00:00:00 2001
From: eug-vs <eug-vs@keemail.me>
Date: Sun, 14 Jun 2020 15:35:04 +0300
Subject: fix: fetch user correctly

---
 src/Form/SignInForm.tsx | 21 +++++++--------------
 1 file changed, 7 insertions(+), 14 deletions(-)

(limited to 'src/Form/SignInForm.tsx')

diff --git a/src/Form/SignInForm.tsx b/src/Form/SignInForm.tsx
index 40352fe..efe85ed 100644
--- a/src/Form/SignInForm.tsx
+++ b/src/Form/SignInForm.tsx
@@ -26,24 +26,17 @@ const SignInForm: React.FC<PropTypes> = ({ setUser }) => {
   const classes = useStyles();
   const inputRef = useRef<HTMLInputElement>();
 
-  const getUserProfile = name => {
-    get(`/users?name=${name}`).then(response => {
-      setUser(response.data[0]);
-    });
-  };
-
   const onClick = () => {
-    const value = inputRef.current?.value;
-    if (value) {
-      localStorage.setItem('user', value);
-      getUserProfile(value);
+    const username = inputRef.current?.value;
+    if (username) {
+      get(`/users?name=${username}`).then(response => {
+        const user = response.data[0];
+        setUser(user);
+        localStorage.setItem('userId', user._id);
+      });
     }
   };
 
-  if (localStorage.getItem('user') !== null) {
-    getUserProfile(localStorage.getItem('user'));
-  }
-
   return (
     <form className={classes.root} noValidate autoComplete="off">
       <h1>Sign In</h1>
-- 
cgit v1.2.3

