What represents you?no_redirect=1

I'm having some problems with implementing PrivateRoute in React. Here is my code:

When user posts credentials (or App main component gets rendered) onAuth method gets invoked and sets (or not) property of App's state. This property is null (when user is not authenticated) and represents userdetails such like id and username (when user is authenticated). Then, in PrivateRoute based on that property component gets rendered or application redirects user back to the login page. And that doesn't work well. I mean when i'm already authenticated and try to access any of private route, i am redirected to proper component. Problem occurs in 2 situations:

  1. right after logging in - application doesnt redirect me to component i want to access, insted i stay on the login page.
  2. refreshing page (in browser) corresponded to private route.

It seems like PrivateRoute component doesnt get refreshed when property gets changed, which is kinda weird because i'm using similar approach in ApplicationHeader to display username when user is authenticated (and that is refreshed correctly). So, what am i doing wrong here?

asked Nov 12 '18 at 14:15

peter Schizapeter Schiza

21144 silver badges1414 bronze badges