mirror of
https://github.com/better-auth/better-auth.git
synced 2026-10-20 20:26:55 -05:00
fix: standardize name field masking as an empty string (#7794)
Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Taesu <bytaesu@users.noreply.github.com>
This commit is contained in:
co-authored by
Cursor Agent
Taesu
parent
e4a0a3e011
commit
dfeefc4f58
@@ -256,7 +256,7 @@ export const callbackOAuth = createAuthEndpoint(
|
||||
...userInfo,
|
||||
id: String(userInfo.id),
|
||||
email: userInfo.email,
|
||||
name: userInfo.name || userInfo.email,
|
||||
name: userInfo.name || "",
|
||||
},
|
||||
account: accountData,
|
||||
callbackURL,
|
||||
|
||||
@@ -407,7 +407,7 @@ export const oAuthProxy = <O extends OAuthProxyOptions>(opts?: O) => {
|
||||
userInfo: {
|
||||
id: String(userInfo.id),
|
||||
email: userInfo.email,
|
||||
name: userInfo.name || userInfo.email,
|
||||
name: userInfo.name || "",
|
||||
image: userInfo.image,
|
||||
emailVerified: userInfo.emailVerified,
|
||||
},
|
||||
|
||||
@@ -1061,12 +1061,8 @@ describe("Apple Provider", async () => {
|
||||
|
||||
// Name should NOT be the email address
|
||||
expect(session.data?.user.name).not.toBe("user@privaterelay.appleid.com");
|
||||
// Name should be undefined, null, or space when not provided
|
||||
expect(
|
||||
session.data?.user.name === undefined ||
|
||||
session.data?.user.name === null ||
|
||||
session.data?.user.name === " ",
|
||||
).toBe(true);
|
||||
// Name should be empty string when not provided
|
||||
expect(session.data?.user.name).toBe("");
|
||||
});
|
||||
|
||||
it("should use firstName and lastName when provided in token.user", async () => {
|
||||
|
||||
@@ -158,15 +158,15 @@ export const apple = (options: AppleOptions) => {
|
||||
return null;
|
||||
}
|
||||
|
||||
// TODO: " " masking will be removed when the name field is made optional
|
||||
// TODO: "" masking will be removed when the name field is made optional
|
||||
let name: string;
|
||||
if (token.user?.name) {
|
||||
const firstName = token.user.name.firstName || "";
|
||||
const lastName = token.user.name.lastName || "";
|
||||
const fullName = `${firstName} ${lastName}`.trim();
|
||||
name = fullName || " ";
|
||||
name = fullName;
|
||||
} else {
|
||||
name = profile.name || " ";
|
||||
name = profile.name || "";
|
||||
}
|
||||
|
||||
const emailVerified =
|
||||
|
||||
@@ -178,10 +178,7 @@ export const cognito = (options: CognitoOptions) => {
|
||||
return null;
|
||||
}
|
||||
const name =
|
||||
profile.name ||
|
||||
profile.given_name ||
|
||||
profile.username ||
|
||||
profile.email;
|
||||
profile.name || profile.given_name || profile.username || "";
|
||||
const enrichedProfile = {
|
||||
...profile,
|
||||
name,
|
||||
@@ -220,7 +217,11 @@ export const cognito = (options: CognitoOptions) => {
|
||||
return {
|
||||
user: {
|
||||
id: userInfo.sub,
|
||||
name: userInfo.name || userInfo.given_name || userInfo.username,
|
||||
name:
|
||||
userInfo.name ||
|
||||
userInfo.given_name ||
|
||||
userInfo.username ||
|
||||
"",
|
||||
email: userInfo.email,
|
||||
image: userInfo.picture,
|
||||
emailVerified: userInfo.email_verified,
|
||||
|
||||
@@ -170,7 +170,7 @@ export const github = (options: GithubOptions) => {
|
||||
return {
|
||||
user: {
|
||||
id: profile.id,
|
||||
name: profile.name || profile.login,
|
||||
name: profile.name || profile.login || "",
|
||||
email: profile.email,
|
||||
image: profile.avatar_url,
|
||||
emailVerified,
|
||||
|
||||
@@ -141,7 +141,7 @@ export const gitlab = (options: GitlabOptions) => {
|
||||
return {
|
||||
user: {
|
||||
id: profile.id,
|
||||
name: profile.name ?? profile.username,
|
||||
name: profile.name ?? profile.username ?? "",
|
||||
email: profile.email,
|
||||
image: profile.avatar_url,
|
||||
emailVerified: profile.email_verified ?? false,
|
||||
|
||||
@@ -104,7 +104,7 @@ export const huggingface = (options: HuggingFaceOptions) => {
|
||||
return {
|
||||
user: {
|
||||
id: profile.sub,
|
||||
name: profile.name || profile.preferred_username,
|
||||
name: profile.name || profile.preferred_username || "",
|
||||
email: profile.email,
|
||||
image: profile.picture,
|
||||
emailVerified: profile.email_verified ?? false,
|
||||
|
||||
@@ -161,7 +161,7 @@ export const kakao = (options: KakaoOptions) => {
|
||||
const kakaoProfile = account.profile || {};
|
||||
const user = {
|
||||
id: String(profile.id),
|
||||
name: kakaoProfile.nickname || account.name || undefined,
|
||||
name: kakaoProfile.nickname || account.name || "",
|
||||
email: account.email,
|
||||
image:
|
||||
kakaoProfile.profile_image_url || kakaoProfile.thumbnail_image_url,
|
||||
|
||||
@@ -147,7 +147,7 @@ export const line = (options: LineOptions) => {
|
||||
const userMap = await options.mapProfileToUser?.(profile as any);
|
||||
// ID preference order
|
||||
const id = (profile as any).sub || (profile as any).userId;
|
||||
const name = (profile as any).name || (profile as any).displayName;
|
||||
const name = (profile as any).name || (profile as any).displayName || "";
|
||||
const image =
|
||||
(profile as any).picture || (profile as any).pictureUrl || undefined;
|
||||
const email = (profile as any).email;
|
||||
|
||||
@@ -96,7 +96,7 @@ export const naver = (options: NaverOptions) => {
|
||||
const res = profile.response || {};
|
||||
const user = {
|
||||
id: res.id,
|
||||
name: res.name || res.nickname,
|
||||
name: res.name || res.nickname || "",
|
||||
email: res.email,
|
||||
image: res.profile_image,
|
||||
emailVerified: false,
|
||||
|
||||
@@ -94,7 +94,7 @@ export const notion = (options: NotionOptions) => {
|
||||
return {
|
||||
user: {
|
||||
id: userProfile.id,
|
||||
name: userProfile.name || "Notion User",
|
||||
name: userProfile.name || "",
|
||||
email: userProfile.person?.email || null,
|
||||
image: userProfile.avatar_url,
|
||||
emailVerified: false,
|
||||
|
||||
@@ -104,11 +104,7 @@ export const paybin = (options: PaybinOptions) => {
|
||||
return {
|
||||
user: {
|
||||
id: user.sub,
|
||||
name:
|
||||
user.name ||
|
||||
user.preferred_username ||
|
||||
(user.email ? user.email.split("@")[0] : "User") ||
|
||||
"User",
|
||||
name: user.name || user.preferred_username || "",
|
||||
email: user.email,
|
||||
image: user.picture,
|
||||
emailVerified: user.email_verified || false,
|
||||
|
||||
@@ -96,7 +96,7 @@ export const polar = (options: PolarOptions) => {
|
||||
return {
|
||||
user: {
|
||||
id: profile.id,
|
||||
name: profile.public_name || profile.username,
|
||||
name: profile.public_name || profile.username || "",
|
||||
email: profile.email,
|
||||
image: profile.avatar_url,
|
||||
emailVerified: profile.email_verified ?? false,
|
||||
|
||||
@@ -197,7 +197,8 @@ export const tiktok = (options: TiktokOptions) => {
|
||||
user: {
|
||||
email: profile.data.user.email || profile.data.user.username,
|
||||
id: profile.data.user.open_id,
|
||||
name: profile.data.user.display_name || profile.data.user.username,
|
||||
name:
|
||||
profile.data.user.display_name || profile.data.user.username || "",
|
||||
image: profile.data.user.avatar_large_url,
|
||||
emailVerified: false,
|
||||
},
|
||||
|
||||
@@ -73,7 +73,7 @@ export const vercel = (options: VercelOptions) => {
|
||||
return {
|
||||
user: {
|
||||
id: profile.sub,
|
||||
name: profile.name ?? profile.preferred_username,
|
||||
name: profile.name ?? profile.preferred_username ?? "",
|
||||
email: profile.email,
|
||||
image: profile.picture,
|
||||
emailVerified: profile.email_verified ?? false,
|
||||
|
||||
@@ -1674,7 +1674,7 @@ export const callbackSSO = (options?: SSOOptions) => {
|
||||
const linked = await handleOAuthUserInfo(ctx, {
|
||||
userInfo: {
|
||||
email: userInfo.email,
|
||||
name: userInfo.name || userInfo.email,
|
||||
name: userInfo.name || "",
|
||||
id: userInfo.id,
|
||||
image: userInfo.image,
|
||||
emailVerified: options?.trustEmailVerified
|
||||
@@ -2216,7 +2216,8 @@ export const callbackSSOSAML = (options?: SSOOptions) => {
|
||||
.filter(Boolean)
|
||||
.join(" ") ||
|
||||
attributes[mapping.name || "displayName"] ||
|
||||
extract.nameID,
|
||||
extract.nameID ||
|
||||
"",
|
||||
emailVerified:
|
||||
options?.trustEmailVerified && mapping.emailVerified
|
||||
? ((attributes[mapping.emailVerified] || false) as boolean)
|
||||
@@ -2253,7 +2254,7 @@ export const callbackSSOSAML = (options?: SSOOptions) => {
|
||||
const result = await handleOAuthUserInfo(ctx, {
|
||||
userInfo: {
|
||||
email: userInfo.email as string,
|
||||
name: (userInfo.name || userInfo.email) as string,
|
||||
name: (userInfo.name || "") as string,
|
||||
id: userInfo.id as string,
|
||||
emailVerified: Boolean(userInfo.emailVerified),
|
||||
},
|
||||
@@ -2698,7 +2699,8 @@ export const acsEndpoint = (options?: SSOOptions) => {
|
||||
.filter(Boolean)
|
||||
.join(" ") ||
|
||||
attributes[mapping.name || "displayName"] ||
|
||||
extract.nameID,
|
||||
extract.nameID ||
|
||||
"",
|
||||
emailVerified:
|
||||
options?.trustEmailVerified && mapping.emailVerified
|
||||
? ((attributes[mapping.emailVerified] || false) as boolean)
|
||||
@@ -2736,7 +2738,7 @@ export const acsEndpoint = (options?: SSOOptions) => {
|
||||
const result = await handleOAuthUserInfo(ctx, {
|
||||
userInfo: {
|
||||
email: userInfo.email as string,
|
||||
name: (userInfo.name || userInfo.email) as string,
|
||||
name: (userInfo.name || "") as string,
|
||||
id: userInfo.id as string,
|
||||
emailVerified: Boolean(userInfo.emailVerified),
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user