[英]React.js how to get user roles from jwt token
I'm having a problem with authorization in react.js.我在 react.js 中遇到授权问题。 I want to store user roles in application context but I don't know how to get them from JWT token.我想在应用程序上下文中存储用户角色,但我不知道如何从 JWT 令牌中获取它们。 I found 3 possible solutions, which one of them is the best?我找到了 3 种可能的解决方案,其中哪一种是最好的?
Maybe there is some better option that I don't know.也许有一些我不知道的更好的选择。 Thanks for all advices.感谢您的所有建议。
This is the way to do it,这是做到这一点的方法,
return user roles with jwt token ( something like { token: , roles: } ).返回带有 jwt 令牌的用户角色(类似于 { token: , roles: } )。
but you don't have to do anything, let the backend do the stuff但是你不需要做任何事情,让后端做这些事情
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.