Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: incorrect assignment of displayName for Apple OAuth #425

Merged
merged 8 commits into from
Nov 6, 2023
23 changes: 17 additions & 6 deletions src/routes/oauth/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { GrantProvider, GrantResponse } from 'grant';
import jwt from 'jsonwebtoken';
import { NormalisedProfile } from './utils';
export const OAUTH_ROUTE = '/signin/provider';
import { logger } from '@/logger';

const azureBaseUrl = 'https://login.microsoftonline.com';
const workosBaseUrl = 'https://api.workos.com/sso';
Expand Down Expand Up @@ -54,12 +55,22 @@ export const PROVIDERS_CONFIG: Record<
profile: ({ jwt, profile }) => {
const payload = jwt?.id_token?.payload;

const isProfileError = typeof profile === 'object' && profile.error;
const userProfile = !isProfileError ? JSON.parse(profile) : null;
const displayName =
isProfileError && !userProfile
? payload.email
: `${userProfile.name.firstName} ${userProfile.name.lastName}`;
let displayName;

if (profile) {
try {
const userProfile = JSON.parse(profile);

displayName = userProfile.name
? `${userProfile.name.firstName} ${userProfile.name.lastName}`
: displayName;
} catch (error) {
logger.warn(error);
totzk9 marked this conversation as resolved.
Show resolved Hide resolved

// use the user's email as fallback
displayName = payload.email;
}
}

return {
id: payload.sub,
Expand Down