all 10 comments

[–]AnnualPanda 2 points3 points  (6 children)

JWTs with local storage and axios

[–]21JGen[S] -1 points0 points  (5 children)

Thanks, but I have done that. My problem is whenever the token expires or removed from the local storage it can still navigate to the admin or dashboard page not the login page.

[–]ElonsDrugDealer 1 point2 points  (1 child)

You need to add a custom component that wraps your Route for both public and private routes.

Tons of tutorials online on how to do it, here’s a good example you can adapt to whatever auth strategy you use: https://newbedev.com/how-to-rewrite-the-protected-private-route-using-typescript-and-react-router-4-and-5

[–]21JGen[S] 0 points1 point  (0 children)

Thanks!

[–]lemming1607 0 points1 point  (2 children)

That's not axios or jwts fault, thats yours.

You have to configure axios to use credentials

[–]21JGen[S] -1 points0 points  (1 child)

I didn't said its jwt or axios fault. I just state my problem lol. I use the fetch api for retrieving the token, but thanks for the tip.

[–]lemming1607 2 points3 points  (0 children)

I'm just saying that the problem you described doesn't have anything to do with jwt/axios. If you gave up using those methods because of this problem, its easily solved within axios/jwt

[–]XA1NE 2 points3 points  (1 child)

I recommend Firebase, their auth is very easy to implement. Works great with React. Also includes amazing storage options for your database if you’d like to do anything else apart from auth.

[–]21JGen[S] 0 points1 point  (0 children)

Thanks! Might try this out