fix: Multiple API calls when bypassing /login
This commit is contained in:
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user