Absolutely excellent article Mateusz! :D what a lifesaver! ...just a small heads up :) not sure if intentional - the hook you create is called useAuth but after that, you mention const isAuthenticated = useWithAuth(true) - maybe a small typo?
When the user is on the unprotected page, and for whatever reason his token expires, I want to silently log him out, without redirecting him to the login page.
I'll update the example code with this redirect flag :)
Absolutely excellent article Mateusz! :D what a lifesaver! ...just a small heads up :) not sure if intentional - the hook you create is called
useAuth
but after that, you mentionconst isAuthenticated = useWithAuth(true)
- maybe a small typo?Yeh, a typo, it should be useAuth. Fixed it, thank you Henrick! :)
useAuth(true)
- could you explain how you pass in the boolean param?I originally used it to decide if I want to be redirected or not:
When the user is on the unprotected page, and for whatever reason his token expires, I want to silently log him out, without redirecting him to the login page.
I'll update the example code with this redirect flag :)
That functionality sounds great :) thanks for updating!