[PR #6857] [MERGED] fix(organization): allow internal organization creation when disabled for client #23827

Closed
opened 2026-04-15 22:00:30 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/6857
Author: @GautamBytes
Created: 12/18/2025
Status: Merged
Merged: 12/18/2025
Merged by: @himself65

Base: canaryHead: fix/org-creation-internal-bypass


📝 Commits (2)

  • 6b31a4f fix(org): allow internal organization creation when restricted for users
  • 15a12fa added test case

📊 Changes

2 files changed (+31 additions, -1 deletions)

View changed files

📝 packages/better-auth/src/plugins/organization/routes/crud-org.test.ts (+28 -0)
📝 packages/better-auth/src/plugins/organization/routes/crud-org.ts (+3 -1)

📄 Description

This fixes an issue where using auth.api.createOrganization inside database hooks (like user.create.after) would fail if allowUserToCreateOrganization was set to false.

The Change I updated createOrganization to detect "system actions" (calls made without a session but with an explicit userId, which happens during internal API calls). These trusted internal calls now bypass the allowUserToCreateOrganization config check.

Fixes #6791


Summary by cubic

Allow internal system calls to create organizations even when user org creation is disabled. Detects system actions (no session + explicit userId) in createOrganization and bypasses allowUserToCreateOrganization, fixing failures in hooks like user.create.after.

Written for commit 15a12fa5e8. Summary will update automatically on new commits.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/6857 **Author:** [@GautamBytes](https://github.com/GautamBytes) **Created:** 12/18/2025 **Status:** ✅ Merged **Merged:** 12/18/2025 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `fix/org-creation-internal-bypass` --- ### 📝 Commits (2) - [`6b31a4f`](https://github.com/better-auth/better-auth/commit/6b31a4fece147b72311f676eccdad4ff8ec6d5ca) fix(org): allow internal organization creation when restricted for users - [`15a12fa`](https://github.com/better-auth/better-auth/commit/15a12fa5e8f0a5bda77343bc21bb4fbb7dba2fc8) added test case ### 📊 Changes **2 files changed** (+31 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/plugins/organization/routes/crud-org.test.ts` (+28 -0) 📝 `packages/better-auth/src/plugins/organization/routes/crud-org.ts` (+3 -1) </details> ### 📄 Description This fixes an issue where using auth.api.createOrganization inside database hooks (like user.create.after) would fail if allowUserToCreateOrganization was set to false. The Change I updated createOrganization to detect "system actions" (calls made without a session but with an explicit userId, which happens during internal API calls). These trusted internal calls now bypass the allowUserToCreateOrganization config check. Fixes #6791 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Allow internal system calls to create organizations even when user org creation is disabled. Detects system actions (no session + explicit userId) in createOrganization and bypasses allowUserToCreateOrganization, fixing failures in hooks like user.create.after. <sup>Written for commit 15a12fa5e8f0a5bda77343bc21bb4fbb7dba2fc8. Summary will update automatically on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-15 22:00:30 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#23827