diff options
author | eug-vs <eug-vs@keemail.me> | 2020-06-14 15:35:04 +0300 |
---|---|---|
committer | eug-vs <eug-vs@keemail.me> | 2020-06-14 15:35:04 +0300 |
commit | 3cff0821a8989afca1effb5420d8d0d55d513dbf (patch) | |
tree | 858e7d0ffdb9c59653e1d9077ac1254e2b867721 /src/Form/SignInForm.tsx | |
parent | f13adb846e96d6a4b7f4edc00438253fd26aa031 (diff) | |
download | which-ui-3cff0821a8989afca1effb5420d8d0d55d513dbf.tar.gz |
fix: fetch user correctly
Diffstat (limited to 'src/Form/SignInForm.tsx')
-rw-r--r-- | src/Form/SignInForm.tsx | 21 |
1 files changed, 7 insertions, 14 deletions
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> |