Advertisement
Guest User

Untitled

a guest
Feb 21st, 2018
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. import React, {Component} from 'react';
  2. import { connect } from 'react-redux';
  3. import { routerActions } from 'react-router-redux';
  4. import { bindActionCreators } from 'redux';
  5. import * as authActions from '../actions/authactions'
  6.  
  7. export let RequireAuthentication = (PassedComponent) => {
  8.  
  9.  
  10. class RenderComponent extends Component {
  11.  
  12. componentWillMount(){
  13.  
  14. const {dispatch} = this.props
  15. const token = localStorage.login;
  16. const target = this.props.location.pathname+this.props.location.search;
  17. if (token) {
  18. if (!this.props.auth.account) {
  19. dispatch(authActions.loginSuccess(target))
  20. // dispatch(routerActions.push('/login?target='+this.props.router.location.pathname))
  21. }
  22. }else {
  23. if (!this.props.auth.loggingIn) {
  24. dispatch(routerActions.push('/login?target=/dashboard'))
  25. }
  26. }
  27. }
  28.  
  29. render(){
  30. return (
  31. <PassedComponent {...this.props}/>
  32. )
  33. }
  34. }
  35.  
  36. function mapStateToProps(state) {
  37. return {
  38. auth: state.auth,
  39. router: state.router,
  40. }
  41. }
  42.  
  43. return connect(mapStateToProps)(RenderComponent)
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement