diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2020-09-20 17:56:56 -0700 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2020-09-20 17:56:56 -0700 |
commit | b2cd88bbbad82654057cec8aec7415a8caca667e (patch) | |
tree | c9d8485cdd5f2e4fd7558b963d095027c3913e86 /modern/src/LoginPage.js | |
parent | fc990dcc50650862c4f12a1a530b98bbd36ea4b8 (diff) | |
download | trackermap-web-b2cd88bbbad82654057cec8aec7415a8caca667e.tar.gz trackermap-web-b2cd88bbbad82654057cec8aec7415a8caca667e.tar.bz2 trackermap-web-b2cd88bbbad82654057cec8aec7415a8caca667e.zip |
Use async functions
Diffstat (limited to 'modern/src/LoginPage.js')
-rw-r--r-- | modern/src/LoginPage.js | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/modern/src/LoginPage.js b/modern/src/LoginPage.js index 429a6e6f..2636c807 100644 --- a/modern/src/LoginPage.js +++ b/modern/src/LoginPage.js @@ -63,17 +63,17 @@ const LoginPage = () => { // TODO: Implement registration } - const handleLogin = (event) => { + const handleLogin = async (event) => { event.preventDefault(); - fetch('/api/session', { method: 'POST', body: new URLSearchParams(`email=${email}&password=${password}`) }).then(response => { - if (response.ok) { - dispatch(sessionActions.authenticated(true)); - history.push('/'); - } else { - setFailed(true); - setPassword(''); - } - }); + const response = await fetch('/api/session', { method: 'POST', body: new URLSearchParams(`email=${email}&password=${password}`) }); + if (response.ok) { + const user = await response.json(); + dispatch(sessionActions.updateUser(user)); + history.push('/'); + } else { + setFailed(true); + setPassword(''); + } } return ( |