0

I have an authentication state that I use through the Provider/Consumer context API in React 16.

I initially set the state of this property in my main App to false and then for any restricted components (i.e. that require being authenticated) I make a query to the backend to check if the current token on the client-side is valid.

Thus, I want authentication to always be consumed as false initially by any components when users change browser URLs.

How can I reset authentication on each route change? I am listening on history.listen but if I call setState there is no guarantee that authentication will get set to the false state before the component initially renders.

Adam Thompson
  • 3,278
  • 3
  • 22
  • 37

0 Answers0