mirror of
https://github.com/idanoo/GoScrobble
synced 2025-07-01 21:52:19 +00:00
0.0.3
- 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:
parent
5fd9d41069
commit
038823055a
23 changed files with 413 additions and 178 deletions
|
@ -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
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue