diff options
Diffstat (limited to 'modern/src/LoginPage.js')
-rw-r--r-- | modern/src/LoginPage.js | 7 |
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(''); |