client/src/utils/requireAuth.js
/**
 * @description authentication class for protected routes
 *
 * @class ValidateUser
 *
 * @param  {object} ChildComponent the child component to be rendered
 *
 */
@description authentication class for protected routes
@class ValidateUser

@param  {object} ChildComponent the child component to be rendered
@description authentication class for protected routes @class ValidateUser @param { object } ChildComponent the child component to be rendered
function ValidateUser(ChildComponent) {
  class Authenticate extends PureComponent {
    componentWillMount() {
      const JWT_SECRET = process.env.JWT_SECRET || '!s_aka*@#0';
      const token = localStorage.getItem('token');
      if (!token) {
        this.props.signOut();
      } else if (token) {
        jsonwebtoken.verify(token, JWT_SECRET, (error, decoded) => {
          if (error || decoded.exp < (new Date().getTime() / 1000)) {
            this.props.signOut();
          }
        });
      }
    }
    render() {
      return (
        <ChildComponent {...this.props} />
      );
    }
  }
  Authenticate.propTypes = {
    signOut: PropTypes.func.isRequired
  };
  return connect(null, { signOut })(Authenticate);
}
function ValidateUser ( ChildComponent ) { class Authenticate extends PureComponent { componentWillMount ( ) { const JWT_SECRET = process . env . JWT_SECRET || '!s_aka*@#0' ; const token = localStorage . getItem ( 'token' ) ; if ( ! token ) { this . props . signOut ( ) ; } else if ( token ) { jsonwebtoken . verify ( token , JWT_SECRET , ( error , decoded ) => { if ( error || decoded . exp < ( new Date ( ) . getTime ( ) / 1000 ) ) { this . props . signOut ( ) ; } } ) ; } } render ( ) { return ( < ChildComponent { ... this . props } / > ) ; } } Authenticate . propTypes = { signOut : PropTypes . func . isRequired } ; return connect ( null , { signOut } ) ( Authenticate ) ; }
@description authentication class for protected routes
 @class ValidateUser
@description authentication class for protected routes @class ValidateUser
/**
   * @class AuthenticateUser
   *
   * @classdesc authenticate user component
   *
   */ /**
     * @description validates the authentication status of user
     *
     * @method componentWillMount
     *
     * @return {void} Null
     *
     */ /**
     * @description render - renders the child component
     *
     * @return {object} returns the view object
     *
     */