From 3ccf001e1d98f219b8459bfc849c896890a26cef Mon Sep 17 00:00:00 2001 From: Volnei Munhoz Date: Fri, 19 Dec 2025 09:21:48 -0300 Subject: [PATCH] fix: add name property to delegation credentials for type compatibility (#26022) * fix: add name property to delegation credentials for type compatibility The MultiDisconnectIntegration component expects credentials with user.name property, but delegation credentials only had user.email. This caused a type mismatch when spreading both credential types together in appCredentialsByType handler. Added name: null to the delegation credentials user object to ensure type compatibility. Co-Authored-By: Volnei Munhoz * fix: update getUserDisplayName to check value instead of just property existence The narrowing logic was causing TypeScript to infer 'never' type because after adding name property to delegation credentials, the 'name in user' check always passes. Now we check if name has a truthy value before using it. Also fixed lint warning by using optional chaining for onSuccess callback. Co-Authored-By: Volnei Munhoz * fix: add explicit return type and typeof checks to getUserDisplayName The function now has an explicit return type of string | null and uses typeof checks to ensure proper type narrowing. This prevents TypeScript from inferring a wider return type that includes {} when the user object has properties with non-string types. Co-Authored-By: Volnei Munhoz * test: update delegation credential test to include name property Co-Authored-By: Volnei Munhoz --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- .../components/apps/MultiDisconnectIntegration.tsx | 12 ++++++------ packages/app-store/delegationCredential.test.ts | 2 +- packages/app-store/delegationCredential.ts | 1 + 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/apps/web/components/apps/MultiDisconnectIntegration.tsx b/apps/web/components/apps/MultiDisconnectIntegration.tsx index 3b3c54327e..5ecbecbdcc 100644 --- a/apps/web/components/apps/MultiDisconnectIntegration.tsx +++ b/apps/web/components/apps/MultiDisconnectIntegration.tsx @@ -39,7 +39,7 @@ export function MultiDisconnectIntegration({ credentials, onSuccess }: Props) { const mutation = trpc.viewer.credentials.delete.useMutation({ onSuccess: () => { showToast(t("app_removed_successfully"), "success"); - onSuccess && onSuccess(); + onSuccess?.(); setConfirmationDialogOpen(false); }, onError: () => { @@ -52,12 +52,12 @@ export function MultiDisconnectIntegration({ credentials, onSuccess }: Props) { }, }); - const getUserDisplayName = (user: (typeof credentials)[number]["user"]) => { + const getUserDisplayName = (user: (typeof credentials)[number]["user"]): string | null => { if (!user) return null; - // Check if 'name' property exists on user - if ("name" in user) return user.name; - // Otherwise use email if available - if ("email" in user) return user.email; + // Check if 'name' property exists and has a truthy string value + if ("name" in user && typeof user.name === "string" && user.name) return user.name; + // Otherwise use email if available and it's a string + if ("email" in user && typeof user.email === "string" && user.email) return user.email; return null; }; diff --git a/packages/app-store/delegationCredential.test.ts b/packages/app-store/delegationCredential.test.ts index 8f35b14757..0198402b23 100644 --- a/packages/app-store/delegationCredential.test.ts +++ b/packages/app-store/delegationCredential.test.ts @@ -114,7 +114,7 @@ const buildDelegationCredential = (overrides = {}) => ({ id: -1, delegatedToId: mockDelegationCredential.id, userId: mockUser.id, - user: { email: mockUser.email }, + user: { email: mockUser.email, name: null }, key: { access_token: "NOOP_UNUSED_DELEGATION_TOKEN" }, invalid: false, teamId: null, diff --git a/packages/app-store/delegationCredential.ts b/packages/app-store/delegationCredential.ts index 979d493688..1ef722e6a7 100644 --- a/packages/app-store/delegationCredential.ts +++ b/packages/app-store/delegationCredential.ts @@ -87,6 +87,7 @@ const _buildCommonUserCredential = ({ userId: user.id, user: { email: user.email, + name: null as string | null, }, key: { access_token: "NOOP_UNUSED_DELEGATION_TOKEN",