1
0

feat: 🎸 update decodePayload

This commit is contained in:
kira924age
2023-12-21 21:28:29 +09:00
committed by Toby
parent f8a216574a
commit 3fd594bbb5

View File

@@ -199,11 +199,15 @@ async function importKey(key: string | JsonWebKey, algorithm: SubtleCryptoImport
function decodePayload<T = any>(raw: string): T | undefined { function decodePayload<T = any>(raw: string): T | undefined {
try { try {
const binaryString = atob(raw) const binaryString = atob(raw)
const encodedString = encodeURIComponent(binaryString).replace(/%([0-9A-F]{2})/g, (_match, p1) => { const bytes = new Uint8Array(binaryString.length);
return String.fromCharCode(parseInt(p1, 16)); for (let i = 0; i < binaryString.length; i++) {
}); bytes[i] = binaryString.charCodeAt(i);
}
return JSON.parse(decodeURIComponent(encodedString)); const decoder = new TextDecoder('utf-8');
const decodedString = decoder.decode(bytes);
return JSON.parse(decodedString);
} catch { } catch {
return return
} }