feat: decode base64 to utf8

This commit is contained in:
MingLiang Wang
2022-12-20 19:05:03 +08:00
parent 741419b777
commit dbf942c1fc
@@ -36,10 +36,23 @@ function getToken(): { accessToken: string; refreshToken: string } | null {
}
}
function b64DecodeUnicode(str: string) {
// Going backwards: from byte stream, to percent-encoding, to original string.
return decodeURIComponent(
window
.atob(str)
.split('')
.map(function (c) {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
})
.join('')
);
}
function parseAccessToken(token: string): AccessTokenMessage | null {
try {
const message: AccessTokenMessage = JSON.parse(
window.atob(token.split('.')[1])
b64DecodeUnicode(token.split('.')[1])
);
return message;
} catch (error) {