I am storing JWT in localStorage , lets say my JWT is
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiVVNFUiIsImlhdCI6MTY2MjU1NzE3Mn0.lRbHWxk8kSnTH8Okdko3cK8Nkce-0sNSeTNjQa1m33o
payload is like this
{
"role": "USER",
"iat": 1662557172
}
in my FrontEnd i have a protected route that decodes the JWT then tests the role like this
if (jwt_decode(auth.user).role!=="ADMIN") {
return <Navigate to="/home" />
}
return children
my problem is , if the user creates a new token manually and puts the role as "ADMIN" .
he won't be able to execute any API i know that since the token he created is invalid , but he will be able to enter the ADMIN routes .
is there a way to prevent this ?