17 lines
562 B
TypeScript
17 lines
562 B
TypeScript
import * as plugins from './webjwt.plugins.js';
|
|
|
|
export const getDataFromJwtString = <T = any>(jwtString: string): T => {
|
|
const smartenvInstance = new plugins.smartenv.Smartenv();
|
|
const splitted = jwtString.split('.');
|
|
const dataBase64 = splitted[1];
|
|
let plainJsonString: string;
|
|
if (smartenvInstance.isBrowser) {
|
|
// @ts-ignore
|
|
plainJsonString = atob(dataBase64);
|
|
} else if (smartenvInstance.isNode) {
|
|
let buff = new Buffer(dataBase64, 'base64');
|
|
plainJsonString = buff.toString('ascii');
|
|
}
|
|
return JSON.parse(plainJsonString);
|
|
};
|