SOURCE

function decodeJWT(token) {
  const [headerB64, payloadB64, signature] = token.split('.');
  const payload = JSON.parse(atob(payloadB64));
  // 以下是获取用户信息的示例代码
  const user = {
    id: payload.sub,
    name: payload.name,
    email: payload.email,
    custom_claim: payload.custom_claim,
    userId:payload.userId
    // ... other user information
  };
  return user;
}

var jwt = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c';

jwt='eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJ1c2VyMSIsImV4cCI6MTY5MDI3MzczMDE3NSwiaWF0IjoxNjkwMjcwMTMwMTc1fQ.HHT0_UwEAbiQ35n9A-ClNVxU6QtcE1OheGRk3Mga69jMmtNWQmfhaexY65XjaeEvu0eqkC0pTlOaEKIiXrnz1Q';
jwt='eyJraWQiOiIyMjQ3MzUwMi01MWFjLTQ3NzAtYTk5OS1kNjcyMzM5OGM5OWUiLCJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJtZXNzYWdpbmctY2xpZW50IiwiYXVkIjoibWVzc2FnaW5nLWNsaWVudCIsIm5iZiI6MTY5MDI2MjUyNCwiaXNzIjoiaHR0cDovL2xvY2FsaG9zdDo4MDgwIiwiZXhwIjoxNjkwMjY0MzI0LCJpYXQiOjE2OTAyNjI1MjR9.iIOvExJ3XHa9Upos92h3pRYanXL37QmUjXigLFCHdvmKSVivR29IzKAfZxOmuR7h5A3oTSDfGY3r5-aeEmyxjzDT0kDcsVIpeonNzzWiPmSKzL-HofYJvTKKewUHt6VNZt4kXnsrP6zRNadbBoSitAMuGRewfg5Z22YdRLUD14bbClgWRllhFJza7ROsKZyhkiwjyyx7OL_Nbp5pcrhb_31ToA7PD2Sp0wzN_d0QA482gt12heZJuMZITX6G0bEFiD0ujn8vT9LiJ4ryZeRkA8z8h-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OkPuHTyub8gNm7hPY2LK4UofZ5kKNgnjI0w'
jwt='eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJqaTJ1a084cThZbUk5YTg1UDlTRDdwYTFxWjZzQUdST2xKUDk5WmRSUHowZ1lWZUt5M1JEIS0xMjkxNjUwMjY0IiwiZXhwIjoxNjkwODU1NjYyLCJ1c2VySWQiOiI0MDQzMCIsImlhdCI6MTY5MDg1MjA2Mn0.CTsXU-GEvr2OrK9QD4l1BknnI3TiZmMigUDW-Il5crE';
jwt='eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJjTnEwbXp0QnA5eTZvMlhyLVBhZ2huSmo1eDI4SG1IakxPSFBmSWJsT01LcmlRc0RfemdnIS0xNjgzOTA1NDM2ITE2OTA5NTIyMTk0NTciLCJpc3MiOiJQb3J0YWwgV1MiLCJ1c2VySWQiOiIwMjk4MCIsImlhdCI6MTY5MDk1MzU3NiwiZXhwIjoxNjkwOTU3MTc2fQ.OELvG74grscgGHDFOOMX-t8XXPLwYk3uR-Pv77n7HMc';
const user = decodeJWT(jwt);
//console.log(user);
//console.log(user.userId);


function decodePortalToken(token) {
  const [headerB64, payloadB64, signature] = token.split('.');
  const payload = JSON.parse(atob(payloadB64));
  const claimobj = {
    id: payload.sub,
    name: payload.name,
    userId:payload.userId
  };
  return claimobj;
}
var token = 'eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJjTnEwbXp0QnA5eTZvMlhyLVBhZ2huSmo1eDI4SG1IakxPSFBmSWJsT01LcmlRc0RfemdnIS0xNjgzOTA1NDM2ITE2OTA5NTIyMTk0NTciLCJpc3MiOiJQb3J0YWwgV1MiLCJ1c2VySWQiOiIwMjk4MCIsImlhdCI6MTY5MDk1NDM1MywiZXhwIjoxNjkwOTU3OTUzfQ.pOnswm-SV3cKyfBYIZ4lywf1NIjX0jkAqZAXkVgIarE';
token = 'eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJPc3htIiwidXNlcklkIjoib3NjYXIiLCJyb2xlIjoiYWRtaW4ifQ.hbOYBLS_m3MXJEA3bvGehrHy5uftbsF1zuIG0RSWmzA';
const claimobj = decodeJWT(jwt);
var userId = claimobj.userId; //00001
console.log(userId);
console.log(claimobj.name);
console.log(claimobj);
console 命令行工具 X clear

                    
>
console