Home > Enterprise >  JWT and react, where react gets information from the token
JWT and react, where react gets information from the token

Time:10-20

The question is as follows. After entering data into registration/login form, react sends request to server, in response it gets jwt-token and puts it into localStorage. But how react interacts with the token further, react needs to decrypt the token? For example when I want to get the user's role, which is put into the token, and respectively render pages depending on the role, to do this I need to get the data from the token. Again, to get this data the token is decrypted on the client side?(react)

CodePudding user response:

You need to send a request back to the server with the JWT token and let the server decrypt it and then do whatever you want with the info, you should not decrypt tokens in the client side for security reasons, if you want to get the user role, make a request to the server which retrieves the current user roles and use JWT to get the current user info and also use it as an authorization method.

  • Related