Can anyone help me understand what's going wrong here?
I'm trying to redirect to the login page after a signout.
Here's the code
import React, { Component } from "react";
import firebase from "../Firebase/firebase";
import { withRouter, Redirect } from "react-router-dom";
class Home extends Component {
constructor(props) {
super(props);
this.logout = this.logout.bind(this);
}
state = {};
logout = e => {
e.preventDefault();
firebase
.auth()
.signOut()
.then(
function() {
console.log("Signed Out");
this.props.history.push("/login");
},
function(error) {
console.error("Sign Out Error", error);
}
);
};
render() {
return (
<div align="center" className="container">
<h1> Home page </h1>
<br />
<br />
<h2>Hello: {this.state.user} </h2>
<button
className="btn btn-lg text-white"
style={{ backgroundColor: "#B65DF3" }}
onClick={this.logout}
>
Logout
</button>
</div>
);
}
}
export default withRouter(Home);
Here's the error message
TypeError: Cannot read property 'props' of undefined
I don't understand why it's not working as my login page which redirects here is the exact same and that works.