Created
November 27, 2018 10:42
-
-
Save kvnam/bdda9f9719a2f2c38350120025793fa3 to your computer and use it in GitHub Desktop.
ReactPress Sign out
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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