javascript - How to check the token in localStorage is valid or not?
one text
Solution:
You need to do following code for securing pages
- Add token in redux or localstorage
- On refresh, call api and send token to server that will validate your token
- If validated then you can show protected page otherwise redirect to login
- On server side make middleware that will check if request has token and its valid
- If not valid, send unauthorized response that you can intercept with axios if you are using axios. Or create middleware for response in reactjs
I think this can solve your problem of authenticating user
Source