title: how to redirect user from login to dashboard REACTJS
body: <p>I'm trying to redirect to my user-dashboard page after the user is successfully logged in.
  I've already tried using push('/dashboard') but even if the credentials were false it redirect to the dashboard page any help please !
  So I want when I submit the email and the password correct to login, it will be redirected to the dashboard
  How can i add a condition to test if the user is really authenticated ?</p>
  <pre><code>import React, { Component } from &quot;react&quot;;
  import &quot;./Authentification.css&quot;;
  import PropTypes from &quot;prop-types&quot;;
  import { connect } from &quot;react-redux&quot;;
  import { loginUser } from &quot;../actions/authActions&quot;;
  import { Link } from &quot;react-router-dom&quot;;
  import { Button, TextField } from &quot;@material-ui/core&quot;;
  import axios from &quot;axios&quot;;
  
  class Login extends Component {
    constructor(props) {
      super(props);
      this.state = {
        email: &quot;&quot;,
        password: &quot;&quot;,
        errors: {}
      };
      this.onSubmit = this.onSubmit.bind(this);
      this.handleChange = this.handleChange.bind(this);
    }
    handleChange(event) {
      this.setState({
        [event.target.name]: event.target.value});
    }
    onSubmit = e =&gt; {e.preventDefault();
      const userData = {
        email: this.state.email,
        password: this.state.password
      };
      this.props.loginUser(userData);
      this.props.history.push(&quot;/dashboard&quot;);
    };
  render() {
      return (
        &lt;div className=&quot;hero&quot;&gt;
              &lt;div className=&quot;form-box-login&quot;&gt;
              &lt;img src={logo} className=&quot;image&quot;&gt;&lt;/img&gt;
  
                  &lt;h1 className=&quot;styledh1&quot;&gt;LOGIN&lt;/h1&gt;
                  &lt;form className=&quot;input-group&quot;&gt;
          &lt;form onSubmit={this.onSubmit}&gt;
          &lt;input type=&quot;email&quot;
                       name=&quot;email&quot;
                       value={this.state.email}
                       onChange={this.handleChange}
                        placeholder=&quot;Email&quot; className=&quot;input-field&quot;/&gt;
                      &lt;input type=&quot;password&quot; 
                       name=&quot;password&quot;
                       label=&quot;Password&quot;
                       value={this.state.password}
                       onChange={this.handleChange}
                       placeholder=&quot;Password&quot; className=&quot;input-field&quot;
                       /&gt;
                      &lt;p className=&quot;forgot-password&quot;&gt;Forgot your password?&lt;/p&gt;
                      &lt;button type=&quot;submit&quot; className=&quot;submit-btn&quot;&gt;LOGIN&lt;/button&gt;
                      &lt;/form&gt;
                    
                  &lt;/form&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      );
    }
  }
  
  Login.propTypes = {
    loginUser: PropTypes.func.isRequired,
    auth: PropTypes.object.isRequired,
    errors: PropTypes.object.isRequired
  };
  
  const mapStateToProps = state =&gt; ({
    isAuthenticated: state.auth.isAuthenticated,
    error: state.error
  });
  export default connect(mapStateToProps, {loginUser})(Login);
  </code></pre>