mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-06 08:50:50 +08:00
feat: decode base64 to utf8
This commit is contained in:
@@ -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 {
|
function parseAccessToken(token: string): AccessTokenMessage | null {
|
||||||
try {
|
try {
|
||||||
const message: AccessTokenMessage = JSON.parse(
|
const message: AccessTokenMessage = JSON.parse(
|
||||||
window.atob(token.split('.')[1])
|
b64DecodeUnicode(token.split('.')[1])
|
||||||
);
|
);
|
||||||
return message;
|
return message;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user