Scheduling infrastructure for absolutely everyone.
fix: signup username collision (#25435)
Udit Takkar0f84cedad278
diff --git a/packages/features/auth/lib/next-auth-options.ts b/packages/features/auth/lib/next-auth-options.tsindex bab3b102745..fedc3e958a3 100644--- a/packages/features/auth/lib/next-auth-options.ts+++ b/packages/features/auth/lib/next-auth-options.ts@@ -15,8 +15,8 @@ import { LicenseKeySingleton } from "@calcom/ee/common/server/LicenseKeyService"import { CredentialRepository } from "@calcom/features/credentials/repositories/CredentialRepository";import createUsersAndConnectToOrg from "@calcom/features/ee/dsync/lib/users/createUsersAndConnectToOrg";import ImpersonationProvider from "@calcom/features/ee/impersonation/lib/ImpersonationProvider";-import { getOrgFullOrigin, subdomainSuffix } from "@calcom/features/ee/organizations/lib/orgDomains";import { getOrganizationRepository } from "@calcom/features/ee/organizations/di/OrganizationRepository.container";+import { getOrgFullOrigin, subdomainSuffix } from "@calcom/features/ee/organizations/lib/orgDomains";import { clientSecretVerifier, hostedCal, isSAMLLoginEnabled } from "@calcom/features/ee/sso/lib/saml";import { ProfileRepository } from "@calcom/features/profile/repositories/ProfileRepository";import { UserRepository } from "@calcom/features/users/repositories/UserRepository";@@ -962,7 +962,7 @@ export const getOptions = ({email: user.email,// Slugify the incoming name and append a few random characters to// prevent conflicts for users with the same name.- username: getOrgUsernameFromEmail(user.name, getDomainFromEmail(user.email)),+ username: getOrgUsernameFromEmail(user.email, getDomainFromEmail(user.email)),emailVerified: new Date(Date.now()),name: user.name,identityProvider: idP,diff --git a/packages/features/auth/signup/utils/getOrgUsernameFromEmail.test.ts b/packages/features/auth/signup/utils/getOrgUsernameFromEmail.test.tsindex 62aa8aed79b..d5d1cdb1af5 100644--- a/packages/features/auth/signup/utils/getOrgUsernameFromEmail.test.ts+++ b/packages/features/auth/signup/utils/getOrgUsernameFromEmail.test.ts@@ -16,6 +16,30 @@ describe("getOrgUsernameFromEmail", () => {const result = getOrgUsernameFromEmail(email, autoAcceptEmailDomain);expect(result).toBe("john.doe-example");});++ it("should generate unique usernames for different emails even with same name", () => {+ const email1 = "[email protected]";+ const email2 = "[email protected]";++ const username1 = getOrgUsernameFromEmail(email1, null);+ const username2 = getOrgUsernameFromEmail(email2, null);++ expect(username1).toBe("alice-acme");+ expect(username2).toBe("alice-work-corp");+ expect(username1).not.toBe(username2);+ });++ it("should handle email with plus sign correctly", () => {+ const email = "[email protected]";+ const result = getOrgUsernameFromEmail(email, "example.com");+ expect(result).toBe("bob-test");+ });++ it("should handle null autoAcceptEmailDomain", () => {+ const email = "[email protected]";+ const result = getOrgUsernameFromEmail(email, null);+ expect(result).toBe("user-company");+ });});describe("deriveNameFromOrgUsername", () => {