[GH-ISSUE #1595] Cannot update and delete an organization as user admin (super admin) if we're not a member of this organization #17465

Open
opened 2026-04-15 15:36:38 -05:00 by GiteaMirror · 11 comments
Owner

Originally created by @lauthieb on GitHub (Feb 28, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/1595

Originally assigned to: @ping-maxwell on GitHub.

Is this suited for github?

  • Yes, this is suited for github

Hello,

Is it possible to delete an organization when a user has the "admin" role?
Because today, when I try to delete an organization from an admin user, I have an 403 error that says the user is not a member of this organization (but that's normal, it's an admin).

Thanks in advance for your help!

Describe the solution you'd like

When I do this:

await authClient.organization.delete({
    organizationId: id,
});

and the authenticated user has the role "admin" (but not admin of the organization, admin of the app, like super admin user), he should be able to delete an organization and not receive a 403 error saying "You're not a member of this organization"

Same for updating an organization :)

Describe alternatives you've considered

I didn't consider any alternative, that's more a question.

Additional context

No response

Originally created by @lauthieb on GitHub (Feb 28, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/1595 Originally assigned to: @ping-maxwell on GitHub. ### Is this suited for github? - [x] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. Hello, Is it possible to delete an organization when a user has the "admin" role? Because today, when I try to delete an organization from an admin user, I have an 403 error that says the user is not a member of this organization (but that's normal, it's an admin). Thanks in advance for your help! ### Describe the solution you'd like When I do this: ```tsx await authClient.organization.delete({ organizationId: id, }); ``` and the authenticated user has the role "admin" (but not admin of the organization, admin of the app, like super admin user), he should be able to delete an organization and not receive a 403 error saying "You're not a member of this organization" _Same for updating an organization :)_ ### Describe alternatives you've considered I didn't consider any alternative, that's more a question. ### Additional context _No response_
GiteaMirror added the bugorganization labels 2026-04-15 15:36:38 -05:00
Author
Owner

@stephanmantler commented on GitHub (Apr 20, 2025):

I ended up making a separate "org-admin" plugin to handle a similar use case (needed to merge companies and delete the redundant entry), and I more or less duplicated the implementation from the /organization/delete endpoint.

If you go this route, be sure to also clean up the Member and Invitation tables - while the schema does specify foreign key constraints to Organization, at least in my PostgreSQL database it is ON DELETE NO ACTION so relevant entries need to be removed from those tables, to avoid dangling references to organizations that don't exist any more.

<!-- gh-comment-id:2817022534 --> @stephanmantler commented on GitHub (Apr 20, 2025): I ended up making a separate "org-admin" plugin to handle a similar use case (needed to _merge_ companies and delete the redundant entry), and I more or less duplicated the implementation from the [/organization/delete endpoint](https://github.com/better-auth/better-auth/blob/89cee73335ce021bd15d1474ced1e7b5dd010133/packages/better-auth/src/plugins/organization/routes/crud-org.ts#L344). If you go this route, be sure to also clean up the `Member` and `Invitation` tables - while the schema does specify foreign key constraints to `Organization`, at least in my PostgreSQL database it is `ON DELETE NO ACTION` so relevant entries need to be removed from those tables, to avoid dangling references to organizations that don't exist any more.
Author
Owner

@sebaFP commented on GitHub (Apr 29, 2025):

Hi

I've been investigating this same issue, and I think we could propose a feature enhancement to handle this use case properly.

Currently, the code checks if the user is a member of the organization before checking their permissions, which causes the 403 error for admin users who aren't organization members.

I suggest adding a new option in the organization configuration, similar to how allowUserToCreateOrganization works, but for deletion:

export interface OrganizationOptions {
  // ... existing options
  allowUserToDeleteOrganization?: boolean | ((user: User) => Promise<boolean> | boolean);
}

This would allow us to:

  1. Define which users can delete organizations regardless of their membership
  2. Keep backwards compatibility
  3. Provide flexibility through a boolean or function approach
  4. Handle both simple (boolean) and complex (function) authorization scenarios

Would you consider adding this feature? It would solve the admin/super-admin use case while maintaining the security of the existing implementation for regular users.

<!-- gh-comment-id:2837342059 --> @sebaFP commented on GitHub (Apr 29, 2025): Hi I've been investigating this same issue, and I think we could propose a feature enhancement to handle this use case properly. Currently, the code checks if the user is a member of the organization before checking their permissions, which causes the 403 error for admin users who aren't organization members. I suggest adding a new option in the organization configuration, similar to how `allowUserToCreateOrganization` works, but for deletion: ```typescript export interface OrganizationOptions { // ... existing options allowUserToDeleteOrganization?: boolean | ((user: User) => Promise<boolean> | boolean); } ``` This would allow us to: 1. Define which users can delete organizations regardless of their membership 2. Keep backwards compatibility 3. Provide flexibility through a boolean or function approach 4. Handle both simple (boolean) and complex (function) authorization scenarios Would you consider adding this feature? It would solve the admin/super-admin use case while maintaining the security of the existing implementation for regular users.
Author
Owner

@dosubot[bot] commented on GitHub (Jul 29, 2025):

Hi, @lauthieb. I'm Dosu, and I'm helping the better-auth team manage their backlog and am marking this issue as stale.

Issue Summary:

  • You reported that super admins with the "admin" role cannot update or delete organizations unless they are members, encountering a 403 error.
  • A workaround was shared involving a separate "org-admin" plugin to handle organization deletion, with notes on cleaning up related database entries.
  • A feature enhancement was proposed to add an option in the organization configuration to allow certain users to delete organizations regardless of membership.
  • This proposal has received positive feedback from multiple maintainers as a way to balance security with super-admin capabilities.
  • The issue remains unresolved and open for further discussion or implementation.

Next Steps:

  • Please let me know if this issue is still relevant with the latest version of better-auth by commenting here to keep the discussion active.
  • If I do not hear back within 7 days, I will automatically close this issue to help keep the backlog manageable.

Thank you for your understanding and contribution!

<!-- gh-comment-id:3133155486 --> @dosubot[bot] commented on GitHub (Jul 29, 2025): Hi, @lauthieb. I'm [Dosu](https://dosu.dev), and I'm helping the better-auth team manage their backlog and am marking this issue as stale. **Issue Summary:** - You reported that super admins with the "admin" role cannot update or delete organizations unless they are members, encountering a 403 error. - A workaround was shared involving a separate "org-admin" plugin to handle organization deletion, with notes on cleaning up related database entries. - A feature enhancement was proposed to add an option in the organization configuration to allow certain users to delete organizations regardless of membership. - This proposal has received positive feedback from multiple maintainers as a way to balance security with super-admin capabilities. - The issue remains unresolved and open for further discussion or implementation. **Next Steps:** - Please let me know if this issue is still relevant with the latest version of better-auth by commenting here to keep the discussion active. - If I do not hear back within 7 days, I will automatically close this issue to help keep the backlog manageable. Thank you for your understanding and contribution!
Author
Owner

@lauthieb commented on GitHub (Jul 29, 2025):

Hi, @lauthieb. I'm Dosu, and I'm helping the better-auth team manage their backlog and am marking this issue as stale.

Issue Summary:

  • You reported that super admins with the "admin" role cannot update or delete organizations unless they are members, encountering a 403 error.
  • A workaround was shared involving a separate "org-admin" plugin to handle organization deletion, with notes on cleaning up related database entries.
  • A feature enhancement was proposed to add an option in the organization configuration to allow certain users to delete organizations regardless of membership.
  • This proposal has received positive feedback from multiple maintainers as a way to balance security with super-admin capabilities.
  • The issue remains unresolved and open for further discussion or implementation.

Next Steps:

  • Please let me know if this issue is still relevant with the latest version of better-auth by commenting here to keep the discussion active.
  • If I do not hear back within 7 days, I will automatically close this issue to help keep the backlog manageable.

Thank you for your understanding and contribution!

This issue is still relevant.

<!-- gh-comment-id:3134315023 --> @lauthieb commented on GitHub (Jul 29, 2025): > Hi, [@lauthieb](https://github.com/lauthieb). I'm [Dosu](https://dosu.dev), and I'm helping the better-auth team manage their backlog and am marking this issue as stale. > > **Issue Summary:** > > * You reported that super admins with the "admin" role cannot update or delete organizations unless they are members, encountering a 403 error. > * A workaround was shared involving a separate "org-admin" plugin to handle organization deletion, with notes on cleaning up related database entries. > * A feature enhancement was proposed to add an option in the organization configuration to allow certain users to delete organizations regardless of membership. > * This proposal has received positive feedback from multiple maintainers as a way to balance security with super-admin capabilities. > * The issue remains unresolved and open for further discussion or implementation. > > **Next Steps:** > > * Please let me know if this issue is still relevant with the latest version of better-auth by commenting here to keep the discussion active. > * If I do not hear back within 7 days, I will automatically close this issue to help keep the backlog manageable. > > Thank you for your understanding and contribution! This issue is still relevant.
Author
Owner

@binajmen commented on GitHub (Aug 8, 2025):

Hi

I've been investigating this same issue, and I think we could propose a feature enhancement to handle this use case properly.

Currently, the code checks if the user is a member of the organization before checking their permissions, which causes the 403 error for admin users who aren't organization members.

I suggest adding a new option in the organization configuration, similar to how allowUserToCreateOrganization works, but for deletion:

export interface OrganizationOptions {
  // ... existing options
  allowUserToDeleteOrganization?: boolean | ((user: User) => Promise<boolean> | boolean);
}

This would allow us to:

  1. Define which users can delete organizations regardless of their membership
  2. Keep backwards compatibility
  3. Provide flexibility through a boolean or function approach
  4. Handle both simple (boolean) and complex (function) authorization scenarios

Would you consider adding this feature? It would solve the admin/super-admin use case while maintaining the security of the existing implementation for regular users.

This looks like a very pragmatic solution. @Bekacru could you validate this approach before someone starts working on a PR?

<!-- gh-comment-id:3166567805 --> @binajmen commented on GitHub (Aug 8, 2025): > Hi > > I've been investigating this same issue, and I think we could propose a feature enhancement to handle this use case properly. > > Currently, the code checks if the user is a member of the organization before checking their permissions, which causes the 403 error for admin users who aren't organization members. > > I suggest adding a new option in the organization configuration, similar to how `allowUserToCreateOrganization` works, but for deletion: > > ```typescript > export interface OrganizationOptions { > // ... existing options > allowUserToDeleteOrganization?: boolean | ((user: User) => Promise<boolean> | boolean); > } > ``` > > This would allow us to: > 1. Define which users can delete organizations regardless of their membership > 2. Keep backwards compatibility > 3. Provide flexibility through a boolean or function approach > 4. Handle both simple (boolean) and complex (function) authorization scenarios > > Would you consider adding this feature? It would solve the admin/super-admin use case while maintaining the security of the existing implementation for regular users. > This looks like a very pragmatic solution. @Bekacru could you validate this approach before someone starts working on a PR?
Author
Owner

@stonecobra commented on GitHub (Nov 5, 2025):

Would you need to also add a allowUserToEditOrganization, as the /organization/get-full-organization endpoint also checks membership, but the listOrgs does not, so the admin gets a list that they may not be able to edit or delete

<!-- gh-comment-id:3489086460 --> @stonecobra commented on GitHub (Nov 5, 2025): Would you need to also add a allowUserToEditOrganization, as the /organization/get-full-organization endpoint also checks membership, but the listOrgs does not, so the admin gets a list that they may not be able to edit or delete
Author
Owner

@stonecobra commented on GitHub (Nov 5, 2025):

@okisdev that would work perfectly for my use case. Checking for an uber-role to allow managing organizations.

<!-- gh-comment-id:3491949729 --> @stonecobra commented on GitHub (Nov 5, 2025): @okisdev that would work perfectly for my use case. Checking for an uber-role to allow managing organizations.
Author
Owner

@dosubot[bot] commented on GitHub (Feb 4, 2026):

Hi, @lauthieb. I'm Dosu, and I'm helping the better-auth team manage their backlog and am marking this issue as stale.

Issue Summary:

  • You reported that super admins with the "admin" role cannot update or delete organizations unless they are members, causing 403 errors.
  • A workaround using a custom "org-admin" plugin was shared by another user.
  • A feature enhancement was proposed to add an organization config option (allowUserToDeleteOrganization) to allow deletion regardless of membership.
  • This proposal received positive feedback from maintainers and suggestions to extend similar flexibility to editing permissions.
  • The issue remains open, awaiting validation and potential implementation of this flexible permission approach.

Next Steps:

  • Please let me know if this issue is still relevant with the latest version of better-auth by commenting here to keep the discussion open.
  • Otherwise, I will automatically close this issue in 7 days.

Thanks for your understanding and contribution!

<!-- gh-comment-id:3848367358 --> @dosubot[bot] commented on GitHub (Feb 4, 2026): Hi, @lauthieb. I'm [Dosu](https://dosu.dev), and I'm helping the better-auth team manage their backlog and am marking this issue as stale. **Issue Summary:** - You reported that super admins with the "admin" role cannot update or delete organizations unless they are members, causing 403 errors. - A workaround using a custom "org-admin" plugin was shared by another user. - A feature enhancement was proposed to add an organization config option (allowUserToDeleteOrganization) to allow deletion regardless of membership. - This proposal received positive feedback from maintainers and suggestions to extend similar flexibility to editing permissions. - The issue remains open, awaiting validation and potential implementation of this flexible permission approach. **Next Steps:** - Please let me know if this issue is still relevant with the latest version of better-auth by commenting here to keep the discussion open. - Otherwise, I will automatically close this issue in 7 days. Thanks for your understanding and contribution!
Author
Owner

@lauthieb commented on GitHub (Feb 4, 2026):

Hello, I think it is still relevant.

<!-- gh-comment-id:3848929497 --> @lauthieb commented on GitHub (Feb 4, 2026): Hello, I think it is still relevant.
Author
Owner

@sandros94 commented on GitHub (Feb 12, 2026):

New to better-auth, but as far as I understand it you (platform owner) completely lose control of organizations?

In the current state you are not able to neither create, list, update and delete orgs?

<!-- gh-comment-id:3890716007 --> @sandros94 commented on GitHub (Feb 12, 2026): New to better-auth, but as far as I understand it you (platform owner) completely lose control of organizations? In the current state you are not able to neither create, list, update and delete orgs?
Author
Owner

@ivbaklan2012 commented on GitHub (Mar 19, 2026):

Can I suggest a proposal: it would be very useful to have a "super-admin" be able to perform any actions on the organizations (i.e. adding/removing members, making teams, etc.) and not only update/delete an org.

<!-- gh-comment-id:4088421660 --> @ivbaklan2012 commented on GitHub (Mar 19, 2026): Can I suggest a proposal: it would be very useful to have a "super-admin" be able to perform any actions on the organizations (i.e. adding/removing members, making teams, etc.) and not only update/delete an org.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#17465