aboutsummaryrefslogtreecommitdiff
path: root/modern/src/LoginPage.js
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2020-09-20 17:56:56 -0700
committerAnton Tananaev <anton.tananaev@gmail.com>2020-09-20 17:56:56 -0700
commitb2cd88bbbad82654057cec8aec7415a8caca667e (patch)
treec9d8485cdd5f2e4fd7558b963d095027c3913e86 /modern/src/LoginPage.js
parentfc990dcc50650862c4f12a1a530b98bbd36ea4b8 (diff)
downloadetbsa-traccar-web-b2cd88bbbad82654057cec8aec7415a8caca667e.tar.gz
etbsa-traccar-web-b2cd88bbbad82654057cec8aec7415a8caca667e.tar.bz2
etbsa-traccar-web-b2cd88bbbad82654057cec8aec7415a8caca667e.zip
Use async functions
Diffstat (limited to 'modern/src/LoginPage.js')
-rw-r--r--modern/src/LoginPage.js20
1 files changed, 10 insertions, 10 deletions
diff --git a/modern/src/LoginPage.js b/modern/src/LoginPage.js
index 429a6e6..2636c80 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 (