mirror of
https://github.com/1f349/admin.1f349.com.git
synced 2024-09-19 02:16:46 +01:00
Do not crash if jwt token cannot be parsed
This commit is contained in:
parent
716db16f37
commit
a10ed84d6a
@ -28,6 +28,7 @@
|
||||
let accessToken = login?.tokens?.access;
|
||||
if (accessToken == null) return [];
|
||||
let jwt = parseJwt(accessToken);
|
||||
if(!jwt) return [];
|
||||
return jwt.per.filter((x: string) => x.startsWith("domain:owns=")).map((x: string) => x.slice("domain:owns=".length));
|
||||
}
|
||||
</script>
|
||||
|
@ -32,7 +32,9 @@ export function getBearer() {
|
||||
}
|
||||
|
||||
export function parseJwt(token: string) {
|
||||
const base64Url = token.split(".")[1];
|
||||
const tokenParts = token.split(".");
|
||||
if(tokenParts.length !== 2) return null;
|
||||
const base64Url = tokenParts[1];
|
||||
const base64 = base64Url.replace(/-/g, "+").replace(/_/g, "/");
|
||||
const jsonPayload = decodeURIComponent(
|
||||
window
|
||||
|
Loading…
Reference in New Issue
Block a user