How to decode JWT Token payload on client side?

前端 未结 2 876
暖寄归人
暖寄归人 2021-02-12 18:39

I\'m using a jwt token for authentication and would like to read the payload information on the client-side. Right now I\'m doing something like this:

var payloa         


        
2条回答
  •  臣服心动
    2021-02-12 19:24

    This simple solution returns raw token, header and the payload:

    function jwtDecode(t) {
      let token = {};
      token.raw = t;
      token.header = JSON.parse(window.atob(t.split('.')[0]));
      token.payload = JSON.parse(window.atob(t.split('.')[1]));
      return (token)
    }
    

提交回复
热议问题