From 1ba7a3fa5451184f4fdd8a4a3e4e2076a348b6e1 Mon Sep 17 00:00:00 2001 From: neo773 <62795688+neo773@users.noreply.github.com> Date: Tue, 2 Jun 2026 14:57:10 +0530 Subject: [PATCH] fix: lowercase OAuth handle to prevent duplicate connected accounts (#21120) Google and Microsoft connect flows stored the provider-returned email verbatim, so a re-auth with different casing (Sam@ vs sam@) missed the existing-account lookup and created a duplicate. Normalize the handle to lowercase at extraction, matching the SSO controller. Note: not doing backfill for now --- .../auth/controllers/google-apis-auth.controller.ts | 2 +- .../auth/controllers/microsoft-apis-auth.controller.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/twenty-server/src/engine/core-modules/auth/controllers/google-apis-auth.controller.ts b/packages/twenty-server/src/engine/core-modules/auth/controllers/google-apis-auth.controller.ts index a5b1a7a6df..853b5ab960 100644 --- a/packages/twenty-server/src/engine/core-modules/auth/controllers/google-apis-auth.controller.ts +++ b/packages/twenty-server/src/engine/core-modules/auth/controllers/google-apis-auth.controller.ts @@ -96,7 +96,7 @@ export class GoogleAPIsAuthController { id: workspaceId, }); - const handle = emails[0].value; + const handle = emails[0].value.toLowerCase(); const connectedAccountId = await this.googleAPIsService.refreshGoogleRefreshToken({ diff --git a/packages/twenty-server/src/engine/core-modules/auth/controllers/microsoft-apis-auth.controller.ts b/packages/twenty-server/src/engine/core-modules/auth/controllers/microsoft-apis-auth.controller.ts index 55d024d33e..827666d0dc 100644 --- a/packages/twenty-server/src/engine/core-modules/auth/controllers/microsoft-apis-auth.controller.ts +++ b/packages/twenty-server/src/engine/core-modules/auth/controllers/microsoft-apis-auth.controller.ts @@ -103,7 +103,7 @@ export class MicrosoftAPIsAuthController { ); } - const handle = emails[0].value; + const handle = emails[0].value.toLowerCase(); const connectedAccountId = await this.microsoftAPIsService.refreshMicrosoftRefreshToken({