- Clean up login/redirect flow
- Add redirect when not authed on other endpoints
- Add GET /stats endpoint for overal stats
This commit is contained in:
Daniel Mason 2021-03-30 15:02:04 +13:00
parent 5fd9d41069
commit 038823055a
Signed by: idanoo
GPG key ID: 387387CDBC02F132
23 changed files with 413 additions and 178 deletions

View file

@ -6,6 +6,8 @@ import { Formik, Form, Field } from 'formik';
import ScaleLoader from 'react-spinners/ScaleLoader';
import { connect } from 'react-redux';
import { login } from '../Actions/auth';
import eventBus from "../Actions/eventBus";
import { LOGIN_SUCCESS } from '../Actions/types';
class Login extends React.Component {
constructor(props) {
@ -13,6 +15,14 @@ class Login extends React.Component {
this.state = {username: '', password: '', loading: false};
}
componentDidMount() {
const { history, isLoggedIn } = this.props;
if (isLoggedIn) {
history.push("/dashboard")
}
}
handleLogin(values) {
this.setState({loading: true});
@ -22,9 +32,11 @@ class Login extends React.Component {
.then(() => {
this.setState({
loading: false,
isLoggedIn: true
});
eventBus.dispatch(LOGIN_SUCCESS, { isLoggedIn: true });
history.push("/dashboard");
window.location.reload();
})
.catch(() => {
this.setState({
@ -82,10 +94,8 @@ class Login extends React.Component {
function mapStateToProps(state) {
const { isLoggedIn } = state.auth;
const { message } = state.message;
return {
isLoggedIn,
message
isLoggedIn
};
}