Skip to content

Instantly share code, notes, and snippets.

@kvnam
Created November 27, 2018 10:42
Show Gist options
  • Save kvnam/bdda9f9719a2f2c38350120025793fa3 to your computer and use it in GitHub Desktop.
Save kvnam/bdda9f9719a2f2c38350120025793fa3 to your computer and use it in GitHub Desktop.
ReactPress Sign out
import React, { Component } from "react";
import { connect } from "react-redux";
import { Redirect } from "react-router-dom";
import * as actionTypes from "../../store/actions/index.actions";
class Signout extends Component{
componentDidMount(){
if(this.props.token){
//Dispatch User Signout action
this.props.logoutUser(this.props.token);
}
}
render(){
let authRedirect = null;
if(!this.props.token || this.props.token === ""){
authRedirect = <Redirect to="/" />;
}
return(
<div>
{authRedirect}
</div>
);
}
};
const mapStateToProps = (state) => {
return {
token: state.usersRed.token
};
};
const mapDispatchStateToProps = (dispatch) => {
return {
logoutUser: (token) => {dispatch(actionTypes.userSignout(token))}
}
};
export default connect(mapStateToProps, mapDispatchStateToProps)(Signout);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment