I have a spring boot backend which can send jwt token on login. I need to implement these features in my Astro frontend:
- Redirect to /login if no token is found in local storage
- On login retirieve the token from server response and store it in localStorage
- if any of the requests sent to server return 401 (unauthorized) which will mean token either expired or is not correct -> delete token from localstorage and redirect to /login
- token should be sent with every request in headers: Authorization: Bearer
There is little to no documentation about this for Astro specifically. I have implemented the same thing with my old vue project using store and mutations but I did not find anything remotely simillar with astro though.. Here is the project file I was referring to: https://github.com/salat-23/wafflesproject-frontend/blob/master/src/store/index.js
P.S. I am not a front end developer and dont know a lot of things so any help and tips will be appreciated!