Advertisement
Guest User

Untitled

a guest
Apr 21st, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const requireAuthentication = UserAuthWrapper({
  2.   authSelector: state => state.auth,
  3.   authenticatingSelector: state => state.auth.isAuthenticating,
  4.   predicate: auth => auth.isAuthenticated,
  5.   redirectAction: push,
  6.   wrapperDisplayName: 'UserIsJWTAuthenticated',
  7.   allowRedirectBack: false
  8. });
  9.  
  10. const userIsAdmin = UserAuthWrapper({
  11.   authSelector: state => state.auth,
  12.   redirectAction: push,
  13.   failureRedirectPath: '/customer/' + localStorage.getItem("customerId"),
  14.   wrapperDisplayName: 'UserIsAdmin',
  15.   predicate: auth => auth.isAdmin,
  16.   allowRedirectBack: false
  17. });
  18.  
  19. const router = (
  20.   <Router onUpdate={() => window.scrollTo(0, 0)} history={history}>
  21.     <Route path="/" component={App}>
  22.       <IndexRoute component={requireAuthentication(userIsAdmin(Customers))}/>
  23.       <Route path="/login" component={Login}/>
  24.       <Route path="/invite_customer" component={requireAuthentication(userIsAdmin(CustomerInvite))}/>
  25.       <Route path="/exercise_bank" component={requireAuthentication(userIsAdmin(ExerciseBank))}/>
  26.       <Route path="/customer/:id" component={requireAuthentication(Customer)}/>
  27.       <Route path="*" component={NotFound}/>
  28.     </Route>
  29.   </Router>
  30. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement