Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Feb 22nd, 2018 60 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. import React from "react";
  2. import Route from "react-router-dom/Route";
  3. import Redirect from "react-router-dom/Redirect";
  4. import { connect } from "react-redux";
  5. import withRouter from "react-router-dom/withRouter";
  6. import { verifyToken }  from '../actions/index'
  7.  
  8. class PrivateRouteContainer extends React.Component {
  9.  
  10.   componentDidMount() {
  11.     this.props.verifyToken();
  12.   }
  13.  
  14.   render() {
  15.     const {
  16.       isAuthenticated,
  17.       component: Component,
  18.       location,
  19.       ...props
  20.     } = this.props;
  21.     return (
  22.       <Route
  23.         {...props}
  24.         render={props =>
  25.           isAuthenticated ? (
  26.             <Component {...props} />
  27.           ) : (
  28.             <Redirect
  29.               to={{
  30.                 pathname: "/login",
  31.                 state: { from: location }
  32.               }}
  33.             />
  34.           )}
  35.       />
  36.     );
  37.   }
  38. }
  39.  
  40. const mapStateToProps = state => ({
  41.   isAuthenticated: state.auth.isAuthenticated
  42. });
  43.  
  44. const mapDispatchToProps = dispatch => ({
  45.   verifyToken: () => {
  46.     dispatch(verifyToken())
  47.   }
  48. })
  49.  
  50. export default withRouter(connect(mapStateToProps, mapDispatchToProps)(PrivateRouteContainer));
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top