keycloak-scim/libs/keycloak-masthead/src/util.ts
Erik Jan de Wit b7e4db8e15
Add 'Personal Info' form and masthead to Account UI (#3551)
Co-authored-by: Jon Koops <jonkoops@gmail.com>
2022-11-03 15:06:26 +01:00

19 lines
592 B
TypeScript

import Keycloak from "keycloak-js";
import { TranslateFunction } from "./translation/useTranslation";
export function loggedInUserName(keycloak: Keycloak, t: TranslateFunction) {
if (!keycloak.tokenParsed) {
return t("unknownUser");
}
const givenName = keycloak.tokenParsed.given_name;
const familyName = keycloak.tokenParsed.family_name;
const preferredUsername = keycloak.tokenParsed.preferred_username;
if (givenName && familyName) {
return t("fullName", { givenName, familyName });
}
return givenName || familyName || preferredUsername || t("unknownUser");
}