Skip to content

Fix APIKey in search resolver for get role#16540

Merged
Weiko merged 1 commit intomainfrom
c--fix-api-key-in-search-resolver
Dec 12, 2025
Merged

Fix APIKey in search resolver for get role#16540
Weiko merged 1 commit intomainfrom
c--fix-api-key-in-search-resolver

Conversation

@Weiko
Copy link
Copy Markdown
Member

@Weiko Weiko commented Dec 12, 2025

Fixes #16534

Typing was wrong, apiKey from request object is ApiKeyEntity and not a string which was then failing when using

const roleId = apiKeyRoleMap[apiKeyId];

    if (!isDefined(roleId)) {
      throw new ApiKeyException(
        `API key ${apiKeyId} has no role assigned`,
        ApiKeyExceptionCode.API_KEY_NO_ROLE_ASSIGNED,
      );
    }

error

API key [object Object] has no role assigned"

Before

Screenshot 2025-12-12 at 17 37 06

After

Screenshot 2025-12-12 at 17 36 44

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

Comment on lines 39 to +40
@AuthUserWorkspaceId() userWorkspaceId: string | undefined,
@AuthApiKey() apiKey: string | undefined,
@AuthApiKey() apiKey: ApiKeyEntity | undefined,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The type of apiKey from @AuthApiKey() was updated in one resolver but not in four other files using the same decorator, causing a type mismatch.
Severity: CRITICAL | Confidence: High

🔍 Detailed Analysis

The pull request correctly changes the type of the apiKey parameter from the @AuthApiKey() decorator to ApiKeyEntity in search.resolver.ts. However, this change was not propagated to other resolvers (workspace.resolver.ts, user.resolver.ts, billing.resolver.ts) and controllers (mcp-core.controller.ts) that still declare apiKey as a string. These modules will now receive an ApiKeyEntity object at runtime instead of the expected string. This will cause type mismatches when the apiKey object is passed to downstream services like permissionsService, leading to permission errors or silent failures in workspace and user operations.

💡 Suggested Fix

Update the type of the apiKey parameter from string to ApiKeyEntity in all resolvers and controllers using the @AuthApiKey() decorator (workspace.resolver.ts, user.resolver.ts, billing.resolver.ts, and mcp-core.controller.ts). Ensure that apiKey.id is used to access the string ID where a string is expected by downstream services.

🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location:
packages/twenty-server/src/engine/core-modules/search/search.resolver.ts#L39-L40

Potential issue: The pull request correctly changes the type of the `apiKey` parameter
from the `@AuthApiKey()` decorator to `ApiKeyEntity` in `search.resolver.ts`. However,
this change was not propagated to other resolvers (`workspace.resolver.ts`,
`user.resolver.ts`, `billing.resolver.ts`) and controllers (`mcp-core.controller.ts`)
that still declare `apiKey` as a `string`. These modules will now receive an
`ApiKeyEntity` object at runtime instead of the expected string. This will cause type
mismatches when the `apiKey` object is passed to downstream services like
`permissionsService`, leading to permission errors or silent failures in workspace and
user operations.

Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 7458321

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

@github-actions
Copy link
Copy Markdown
Contributor

🚀 Preview Environment Ready!

Your preview environment is available at: http://bore.pub:1110

This environment will automatically shut down when the PR is closed or after 5 hours.

Copy link
Copy Markdown
Contributor

@etiennejouan etiennejouan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@Weiko Weiko merged commit 62408e7 into main Dec 12, 2025
57 of 63 checks passed
@Weiko Weiko deleted the c--fix-api-key-in-search-resolver branch December 12, 2025 16:54
@twenty-eng-sync
Copy link
Copy Markdown

Hey @Weiko! After you've done the QA of your Pull Request, you can mark it as done here. Thank you!

@Weiko Weiko mentioned this pull request Dec 12, 2025
guillim added a commit that referenced this pull request Dec 15, 2025
Following this #16540
Those were not failing (yet) but were wrongly typed and error prone

---------

Co-authored-by: Guillim <guillim@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

API key [object Object] has no role assigned

2 participants