2

I've got a React app built using react-boilerplate, and I'm unsure of the best way to deal with authentication. Here's my questions:

  1. If a user authenticates, their token is stored in localStorage. If they leave the app and come back, state is cleared, so I'll have to grab their profile picture and such again, as well as check expiration/validity of their token by pinging the server. Where do I do this? Doesn't make sense to add this to EVERY route's onEnter function.

  2. On each subsequent route change, data will obviously be fetched from the server. Each piece of loaded data on the page (maybe it's graphs, products, account info, whatever) will authorize the user since the token is sent in the header of each request. If one or all of the routes come back as unauthorized, do I redirect them? Make the whole page render an error? Just show an unauthorized error on the one/many sections that were unauthorized?? Not sure how this works.

trevorhinesley
  • 845
  • 1
  • 10
  • 36
  • Take a look at these examples: https://medium.com/the-many/adding-login-and-authentication-sections-to-your-react-or-react-native-app-7767fd251bd1#.avpadeg2h – Aaron Beall Mar 03 '17 at 18:22

0 Answers0