Skip to content

Instantly share code, notes, and snippets.

@Mozartted
Created May 25, 2018 10:05
Show Gist options
  • Save Mozartted/0210b4d80335a5b922165c33e6d12b92 to your computer and use it in GitHub Desktop.
Save Mozartted/0210b4d80335a5b922165c33e6d12b92 to your computer and use it in GitHub Desktop.
import React from "react";
import { connect } from "react-redux";
import { withRouter } from "react-router";
class AppCheck extends React.Component {
componentDidUpdate(prevProps) {
const { dispatch, redirectUrl } = this.props;
const isLoggingOut = prevProps.isLoggedIn && !this.props.isLoggedIn;
const isLoggingIn = !prevProps.isLoggedIn && this.props.isLoggedIn;
if (isLoggingIn) {
// dispatch(navigateTo(redirectUrl))
} else if (isLoggingOut) {
// do any kind of cleanup or post-logout redirection here
}
}
render() {
return this.props.children;
}
}
const mapStateToProps = state => {
console.log(state);
return {
isLoggedIn: state.isAuthenticated,
redirectUrl: state.redirectUrl
};
};
export default withRouter(connect(mapStateToProps)(AppCheck));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment