1
0

refactor: 💡 reafactor decodePayload

This commit is contained in:
kira924age
2023-12-21 21:50:12 +09:00
committed by Toby
parent 5432f1997e
commit c3ecbf64c9

View File

@@ -198,14 +198,8 @@ 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 bytes = Array.from(atob(raw), char => char.charCodeAt(0));
const bytes = new Uint8Array(binaryString.length); const decodedString = new TextDecoder('utf-8').decode(new Uint8Array(bytes));
for (let i = 0; i < binaryString.length; i++) {
bytes[i] = binaryString.charCodeAt(i);
}
const decoder = new TextDecoder('utf-8');
const decodedString = decoder.decode(bytes);
return JSON.parse(decodedString); return JSON.parse(decodedString);
} catch { } catch {