authService is there a method to decode the token?

is there a built in method, perhaps in Auth Service or another on of the related services, to decode the token and get to data within?

Assuming you don’t need to verify the token and just want its value, you could use a function like this:

function decodeJWT(token) {
const parts = token.split(‘.’);
const payload = parts[1];
const decoded = Buffer.from(payload, ‘base64url’).toString(‘utf8’);
return JSON.parse(decoded);
}

1 Like