import { jwtDecode } from "jwt-decode";
const AUTH0_BASE_CLAIM = `https://camunda.com`;
const AUTH0_TOKEN_ATTRIBUTE_SETTINGS = "settings";
const AUTH0_TOKEN_ATTRIBUTE_META = "meta";
const AUTH0_TOKEN_ATTRIBUTE_PERSONA = "persona";
export const getPersona = (token) => token[`${AUTH0_BASE_CLAIM}/${AUTH0_TOKEN_ATTRIBUTE_SETTINGS}`]?.[AUTH0_TOKEN_ATTRIBUTE_PERSONA];
export const getMeta = (token) => token[`${AUTH0_BASE_CLAIM}/${AUTH0_TOKEN_ATTRIBUTE_META}`];
export const decodeJWT = (userToken) => {
    let decodedToken = null;
    try {
        decodedToken = jwtDecode(userToken);
    }
    catch (_) {
        // do nothing
    }
    return !decodedToken
        ? null
        : {
            decodedToken,
            persona: getPersona(decodedToken),
            meta: getMeta(decodedToken),
            audience: decodedToken.aud,
            userId: decodedToken.sub,
        };
};
