728x90
반응형
jwt decode 를 할 일이 생겼다.
yarn add jwt-decode
라이브러리를 사용하거나,
const parseJwt = (token) => {
try {
return JSON.parse(atob(token.split('.')[1]));
} catch (e) {
console.log('e :::::', e);
return null;
}
};
함수를 사용하면되는데,
invalid base64 for part #2 (Property 'atob' doesn't exist)
라는 에러가 나왔다.
app.tsx에서
import { decode, encode } from 'base-64';
if (!global.btoa) {
global.btoa = encode;
}
if (!global.atob) {
global.atob = decode;
}
로 atob / btoa 를 선언해주면 끝
728x90
반응형