I'm using react router v4 and trying to implement a protected api view. E.g., if a user goes to /add/
url while not logged in, they would be redirected to /login/
, then upon successful login taken to /add/
.
I was able to implement it using the idea from this post. However, I run into issues whenever the initial http request that loads the app is from a protected url.
E.g. when I enter in the browser '/add/'
and hit enter, I run into async issues where my app doesn't have time to make an ajax request to the server to check for login, and as a result the router ends up routing to the /login/
because ajax auth request hasn't completed.
Can someone recommend login workflow should be handled generally, taking into account the fact that a user may start their session on a protected url like '/add/'
and not on the home '/'
?