Guest User

Untitled

a guest
Nov 19th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. const enforceUserAuth = {
  2. authenticate() {
  3. API.get('user/authed', {}, res => {
  4. debugger;
  5. this.isAuthenticated = res.authed;
  6. })
  7. }
  8. }
  9.  
  10. function PrivateRoute({ component: Component, ...rest }) {
  11. return(
  12. <Route {...rest}
  13. render={props => enforceUserAuth.isAuthenticated ?
  14. (<Component {...props} />) :
  15. (<Redirect to={{ pathname: '/login',
  16. state: { source: props.location } }} />)
  17. }
  18. />
  19. )
  20. }
  21.  
  22. function enforceUserAuth() {
  23. let validUser = false;
  24. API.get('user/authed', {}, res => {
  25. validUser = res.authed
  26. return validUser;
  27. })
  28. }
Add Comment
Please, Sign In to add comment