To enhance security and stability of authentication in the frontend, I suggest the following changes:
-
Store token in sessionStorage instead of localStorage
This ensures the token is cleared automatically when the browser tab is closed, reducing the risk of reusing outdated or invalid tokens.
-
Validate token on every page reload
On each initial page load, the frontend should call a backend endpoint to verify whether the token stored in the session is still valid.
If the token is invalid or expired, the user should be redirected to the login page.
To enhance security and stability of authentication in the frontend, I suggest the following changes:
Store token in
sessionStorageinstead oflocalStorageThis ensures the token is cleared automatically when the browser tab is closed, reducing the risk of reusing outdated or invalid tokens.
Validate token on every page reload
On each initial page load, the frontend should call a backend endpoint to verify whether the token stored in the session is still valid.
If the token is invalid or expired, the user should be redirected to the login page.