fix(core): update
This commit is contained in:
12
ts/index.ts
12
ts/index.ts
@@ -1,8 +1,16 @@
|
||||
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];
|
||||
// @ts-ignore
|
||||
return JSON.parse(atob(dataBase64));
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user