fix: displays name from jwt instead of using email address

Signed-off-by: Teun Willems <teun.willems@theapsgroup.com>
This commit is contained in:
Teun Willems
2021-04-01 14:07:24 +02:00
parent 2bbac57ce4
commit 81fa98b3ab
@@ -30,7 +30,7 @@ export const makeProfileInfo = (
profile: passport.Profile,
idToken?: string,
): ProfileInfo => {
const { displayName } = profile;
let { displayName } = profile;
let email: string | undefined = undefined;
if (profile.emails && profile.emails.length > 0) {
@@ -44,7 +44,7 @@ export const makeProfileInfo = (
picture = firstPhoto.value;
}
if ((!email || !picture) && idToken) {
if ((!email || !picture || !displayName) && idToken) {
try {
const decoded: Record<string, string> = jwtDecoder(idToken);
if (!email && decoded.email) {
@@ -53,6 +53,9 @@ export const makeProfileInfo = (
if (!picture && decoded.picture) {
picture = decoded.picture;
}
if (!displayName && decoded.name) {
displayName = decoded.name;
}
} catch (e) {
throw new Error(`Failed to parse id token and get profile info, ${e}`);
}