-
Notifications
You must be signed in to change notification settings - Fork 32
Description
Description:
The ConditionalRoutes component currently restricts access based solely on the presence of a token in localStorage. Because localStorage can be manually edited by any user through the browser's developer tools, someone could "spoof" a login by adding a fake token. While the backend might block data requests, the user would still be able to see the layout of restricted admin or user dashboards.
Solution:
Implement a more robust check that validates the token's authenticity. A common approach is to use a "me" or "validate" query on the initial load to confirm with the server that the token is actually valid before rendering protected content.
Code Implementation:
In client/src/utils/ConditionalRoutes.js, add a check that verifies the user profile with the backend using the token before allowing the route to render. If the server returns an authentication error, clear the local storage and redirect to the login page.