refactor: 💡 reafactor decodePayload
This commit is contained in:
10
src/index.ts
10
src/index.ts
@@ -198,14 +198,8 @@ async function importKey(key: string | JsonWebKey, algorithm: SubtleCryptoImport
|
||||
|
||||
function decodePayload<T = any>(raw: string): T | undefined {
|
||||
try {
|
||||
const binaryString = atob(raw)
|
||||
const bytes = new Uint8Array(binaryString.length);
|
||||
for (let i = 0; i < binaryString.length; i++) {
|
||||
bytes[i] = binaryString.charCodeAt(i);
|
||||
}
|
||||
|
||||
const decoder = new TextDecoder('utf-8');
|
||||
const decodedString = decoder.decode(bytes);
|
||||
const bytes = Array.from(atob(raw), char => char.charCodeAt(0));
|
||||
const decodedString = new TextDecoder('utf-8').decode(new Uint8Array(bytes));
|
||||
|
||||
return JSON.parse(decodedString);
|
||||
} catch {
|
||||
|
||||
Reference in New Issue
Block a user