[GH-ISSUE #6773] Add support for organizationSlug in hasPermission API to allow permission checks using slugs #10623

Closed
opened 2026-04-13 06:51:56 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @ceolinwill on GitHub (Dec 15, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/6773

Is this suited for github?

  • Yes, this is suited for github

Currently, the hasPermission API only supports permission checks using the organizationId. However, many applications use organizationSlug as the primary identifier in routes and UI logic, making it more convenient and user-friendly.

We propose adding support for passing organizationSlug directly to the hasPermission API, allowing developers to verify permissions without needing to resolve or store the organizationId first.

Describe the solution you'd like

await auth.api.hasPermission({
  headers: await headers(),
  body: {
    permissions,
    organizationSlug: workspace,
  },
});

Describe alternatives you've considered

I’m currently using organizationId by performing an additional query beforehand to resolve the organizationSlug to its corresponding ID. While this works, it introduces extra database or API calls, adds complexity to the code, and slightly increases latency in permission checks.

Additional context

This is the same feature request in #3309, which was closed by @dosubot

Originally created by @ceolinwill on GitHub (Dec 15, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/6773 ### Is this suited for github? - [x] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. Currently, the hasPermission API only supports permission checks using the organizationId. However, many applications use organizationSlug as the primary identifier in routes and UI logic, making it more convenient and user-friendly. We propose adding support for passing organizationSlug directly to the hasPermission API, allowing developers to verify permissions without needing to resolve or store the organizationId first. ### Describe the solution you'd like ```ts await auth.api.hasPermission({ headers: await headers(), body: { permissions, organizationSlug: workspace, }, }); ``` ### Describe alternatives you've considered I’m currently using organizationId by performing an additional query beforehand to resolve the organizationSlug to its corresponding ID. While this works, it introduces extra database or API calls, adds complexity to the code, and slightly increases latency in permission checks. ### Additional context This is the same feature request in #3309, which was closed by @dosubot
GiteaMirror added the enhancementlocked labels 2026-04-13 06:51:56 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Dec 15, 2025):

(tag @better-auth-agent if you would like an answer from the Agent)

If you need more help, tag @better-auth-agent in a comment so I can respond.

DiagramDiscordGitHub

Diagram Join Star

<!-- gh-comment-id:3655722461 --> @better-auth-agent[bot] commented on GitHub (Dec 15, 2025): (tag @better-auth-agent if you would like an answer from the Agent) _If you need more help, tag @better-auth-agent in a comment so I can respond._ <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/skyvern_ultra_detailed_interactive.html) • [Discord](https://discord.gg/fG2XXEuQX3) • [GitHub](https://github.com/Skyvern-AI/Skyvern) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/skyvern_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/fG2XXEuQX3) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/Skyvern-AI/Skyvern)
Author
Owner

@dosubot[bot] commented on GitHub (Dec 15, 2025):

Supporting organizationSlug in hasPermission is feasible and aligns with recent patterns in the codebase. Other APIs like listMembers and getActiveMemberRole now accept organizationSlug, resolving it to organizationId internally and returning clear errors if the slug doesn't exist. The organization adapter already provides a findOrganizationBySlug method for this purpose, and the slug field is indexed for efficient lookups, so there are no performance concerns with this approach cite cite.

To implement this, update the hasPermission API schema to accept organizationSlug as an alternative to organizationId. In the endpoint logic, if organizationSlug is provided, resolve it to organizationId using the adapter before proceeding with permission checks. If the slug doesn't exist, return an ORGANIZATION_NOT_FOUND error. This keeps backward compatibility and matches how other endpoints handle slugs cite.

It's a good idea to update documentation and tests to cover the new usage and error cases. This change would simplify permission checks for apps using slugs in their routes and UI, reducing boilerplate and extra queries.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Chat with Dosu Open in Cursor Join Discord Share on X

<!-- gh-comment-id:3655735024 --> @dosubot[bot] commented on GitHub (Dec 15, 2025): <!-- Answer --> Supporting organizationSlug in hasPermission is feasible and aligns with recent patterns in the codebase. Other APIs like listMembers and getActiveMemberRole now accept organizationSlug, resolving it to organizationId internally and returning clear errors if the slug doesn't exist. The organization adapter already provides a findOrganizationBySlug method for this purpose, and the slug field is indexed for efficient lookups, so there are no performance concerns with this approach [cite](https://github.com/better-auth/better-auth/pull/5862) [cite](https://github.com/better-auth/better-auth/pull/6303). To implement this, update the hasPermission API schema to accept organizationSlug as an alternative to organizationId. In the endpoint logic, if organizationSlug is provided, resolve it to organizationId using the adapter before proceeding with permission checks. If the slug doesn't exist, return an ORGANIZATION_NOT_FOUND error. This keeps backward compatibility and matches how other endpoints handle slugs [cite](https://github.com/better-auth/better-auth/blob/a63e70ea27e2e936ae9915171c0e59054dc9b4a0/packages/better-auth/src/plugins/organization/organization.ts#L120-L1067). It's a good idea to update documentation and tests to cover the new usage and error cases. This change would simplify permission checks for apps using slugs in their routes and UI, reducing boilerplate and extra queries. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/ab8c254a-c4a5-46e2-abb6-9f706cd8eb1e?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/ab8c254a-c4a5-46e2-abb6-9f706cd8eb1e?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/ab8c254a-c4a5-46e2-abb6-9f706cd8eb1e?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/ab8c254a-c4a5-46e2-abb6-9f706cd8eb1e?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/ab8c254a-c4a5-46e2-abb6-9f706cd8eb1e?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/ab8c254a-c4a5-46e2-abb6-9f706cd8eb1e?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/ab8c254a-c4a5-46e2-abb6-9f706cd8eb1e?feedback_type=other)</sup> [![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=Supporting%20organizationSlug%20in%20hasPermission%20is%20feasible%20and%20aligns%20with%20recent%20patterns%20in%20the%20codebase.%20Other%20APIs%20like%20listMembers%20and%20getActiveMemberRole%20now%20accept%20organizationSlug%2C%20resolving%20it%20to%20organizationId%20internally%20and%20returning%20clear%20errors%20if%20the%20slug%20doesn%27t%20exist.%20The%20organization%20adapter%20already%20provides%20a%20findOrganizationBySlug%20method%20for%20this%20purpose%2C%20and%20the%20slug%20field%20is%20indexed%20for%20efficient%20lookups%2C%20so%20there%20are%20no%20performance%20concerns%20with%20this%20approach%C2%A0%5Bcite%5D%28https%3A//github.com/better-auth/better-auth/pull/5862%29%C2%A0%5Bcite%5D%28https%3A//github.com/better-auth/better-auth/pull/6303%29.%0A%0ATo%20implement%20this%2C%20update%20the%20hasPermission%20API%20schema%20to%20accept%20organizationSlug%20as%20an%20alternative%20to%20organizationId.%20In%20the%20endpoint%20logic%2C%20if%20organizationSlug%20is%20provided%2C%20resolve%20it%20to%20organizationId%20using%20the%20adapter%20before%20proceeding%20with%20permission%20checks.%20If%20the%20slug%20doesn%27t%20exist%2C%20return%20an%20ORGANIZATION_NOT_FOUND%20error.%20This%20keeps%20backward%20compatibility%20and%20matches%20how%20other%20endpoints%20handle%20slugs%C2%A0%5Bcite%5D%28https%3A//github.com/better-auth/better-auth/blob/a63e70ea27e2e936ae9915171c0e59054dc9b4a0/packages/better-auth/src/plugins/organization/organization.ts%23L120-L1067%29.%0A%0AIt%27s%20a%20good%20idea%20to%20update%20documentation%20and%20tests%20to%20cover%20the%20new%20usage%20and%20error%20cases.%20This%20change%20would%20simplify%20permission%20checks%20for%20apps%20using%20slugs%20in%20their%20routes%20and%20UI%2C%20reducing%20boilerplate%20and%20extra%20queries.)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/6773)
Author
Owner

@github-actions[bot] commented on GitHub (Mar 31, 2026):

This issue has been locked as it was closed more than 7 days ago. If you're experiencing a similar problem or you have additional context, please open a new issue and reference this one.

<!-- gh-comment-id:4165910546 --> @github-actions[bot] commented on GitHub (Mar 31, 2026): This issue has been locked as it was closed more than 7 days ago. If you're experiencing a similar problem or you have additional context, please open a new issue and reference this one.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#10623