mirror of
https://github.com/1f349/admin.1f349.com.git
synced 2024-11-09 22:32:57 +00: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;
|
let accessToken = login?.tokens?.access;
|
||||||
if (accessToken == null) return [];
|
if (accessToken == null) return [];
|
||||||
let jwt = parseJwt(accessToken);
|
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));
|
return jwt.per.filter((x: string) => x.startsWith("domain:owns=")).map((x: string) => x.slice("domain:owns=".length));
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
@ -32,7 +32,9 @@ export function getBearer() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function parseJwt(token: string) {
|
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 base64 = base64Url.replace(/-/g, "+").replace(/_/g, "/");
|
||||||
const jsonPayload = decodeURIComponent(
|
const jsonPayload = decodeURIComponent(
|
||||||
window
|
window
|
||||||
|
Loading…
Reference in New Issue
Block a user