fix: Multiple API calls when bypassing /login

This commit is contained in:
Alexander Polynomdivision
2018-09-23 16:30:14 +02:00
parent 08cd51c2a3
commit be7a616fb5
7 changed files with 41 additions and 13 deletions

View File

@@ -18,6 +18,7 @@ interface IProps {
authenticated: boolean;
history: any;
didLogin: boolean;
setLoading: (state: boolean) => void;
setSnackbar: (state: boolean, msg: string) => void;
loading: boolean;
@@ -54,7 +55,11 @@ const LoginPageWithRouter = withRouter(
componentDidMount() {
// If we're already authenticated, we can skip the login page
if (this.props.authenticated) {
// NOTE: The '!this.props.didLogin' is here, as the Component gets
// remounted, when the auth status changes. Thus we would
// redirect to /dashboard, redirect back to /welcome
// (or /dashboard again) and cause mulitple API calls!
if (this.props.authenticated && !this.props.didLogin) {
this.props.history.push("/dashboard");
}
}