aboutsummaryrefslogtreecommitdiff
path: root/modern/src/LoginPage.js
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2020-06-06 15:38:59 -0700
committerAnton Tananaev <anton.tananaev@gmail.com>2020-06-06 15:38:59 -0700
commitf8643e6bd88c20cc13383a86f457d909cdd6ae6e (patch)
tree8a9ec30921684d822a4346907617d9bb94c12f80 /modern/src/LoginPage.js
parentcc03e41dd7f9f401797f39eb08e7d4617d624a2f (diff)
downloadtrackermap-web-f8643e6bd88c20cc13383a86f457d909cdd6ae6e.tar.gz
trackermap-web-f8643e6bd88c20cc13383a86f457d909cdd6ae6e.tar.bz2
trackermap-web-f8643e6bd88c20cc13383a86f457d909cdd6ae6e.zip
Use proper session state
Diffstat (limited to 'modern/src/LoginPage.js')
-rw-r--r--modern/src/LoginPage.js7
1 files changed, 6 insertions, 1 deletions
diff --git a/modern/src/LoginPage.js b/modern/src/LoginPage.js
index 99ff95b6..20375b98 100644
--- a/modern/src/LoginPage.js
+++ b/modern/src/LoginPage.js
@@ -1,5 +1,7 @@
import React, { useState } from 'react';
+import { useDispatch } from 'react-redux';
import { useHistory } from 'react-router-dom';
+import { sessionActions } from './store';
import Button from '@material-ui/core/Button';
import FormHelperText from '@material-ui/core/FormHelperText';
import FormControl from '@material-ui/core/FormControl';
@@ -44,6 +46,8 @@ const useStyles = makeStyles(theme => ({
}));
const LoginPage = () => {
+ const dispatch = useDispatch();
+
const [failed, setFailed] = useState(false);
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
@@ -67,7 +71,8 @@ const LoginPage = () => {
event.preventDefault();
fetch('/api/session', { method: 'POST', body: new URLSearchParams(`email=${email}&password=${password}`) }).then(response => {
if (response.ok) {
- history.push('/'); // TODO: Avoid calling sessions twice
+ dispatch(sessionActions.authenticated(true));
+ history.push('/');
} else {
setFailed(true);
setPassword('');