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 <[email protected]>

* 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 <[email protected]>

* 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 <[email protected]>

* test: update delegation credential test to include name property

Co-Authored-By: Volnei Munhoz <[email protected]>

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2025-12-19 12:21:48 +00:00
1 parent 4c282ea9ca
commit 3ccf001e1d
3 files changed
+8 -7

No files matched your search

@@ -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;
};
@@ -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,
@@ -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",