[PR #3600] [MERGED] fix: organization allowUserToCreateOrganization user argument typing #30507

Closed
opened 2026-04-17 21:34:27 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/3600
Author: @TimurBas
Created: 7/24/2025
Status: Merged
Merged: 8/1/2025
Merged by: @Bekacru

Base: mainHead: fix/org-allowUserToCreateOrganization-typing


📝 Commits (3)

  • 2ee43ea fix: organization allowUserToCreateOrganization user argument typing
  • eb1f19f Merge branch 'main' into fix/org-allowUserToCreateOrganization-typing
  • e22b4da chore: changeset

📊 Changes

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

View changed files

.changeset/silly-falcons-tie.md (+5 -0)
📝 packages/better-auth/src/plugins/organization/types.ts (+1 -1)

📄 Description

When using the organization plugin and if we have:

allowUserToCreateOrganization(user) {
  return user.role === "internalAdmin";
},

The user argument does not have role in its type definition which led to a type error.
It just looks at schema.ts and uses the userSchema const:

export const userSchema = z.object({
	id: z.string(),
	email: z.string().transform((val) => val.toLowerCase()),
	emailVerified: z.boolean().default(false),
	name: z.string(),
	image: z.string().nullish(),
	createdAt: z.date().default(() => new Date()),
	updatedAt: z.date().default(() => new Date()),
});

as the type definition.

If used in conjuction with the admin plugin I would expect I could get the user's role to check whether it is a regular user or admin. If it is an internal admin role (a custom role) then I would allow organization creation otherwise not.

The jwt plugin's definePayload method deconstructs a user argument which also accepts any fields on the user.

definePayload?: (session: {
            user: User & Record<string, any>;
            session: Session & Record<string, any>;
        }) => Promise<Record<string, any>> | Record<string, any>;

Taken inspiration from that, obviously.


Summary by cubic

Updated the typing for the user argument in allowUserToCreateOrganization to support custom fields like role.


🔄 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/3600 **Author:** [@TimurBas](https://github.com/TimurBas) **Created:** 7/24/2025 **Status:** ✅ Merged **Merged:** 8/1/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `main` ← **Head:** `fix/org-allowUserToCreateOrganization-typing` --- ### 📝 Commits (3) - [`2ee43ea`](https://github.com/better-auth/better-auth/commit/2ee43eaba479e9772af82d6821cd3db4b7db2c24) fix: organization allowUserToCreateOrganization user argument typing - [`eb1f19f`](https://github.com/better-auth/better-auth/commit/eb1f19f5168aa47fb36c1552d7cb7a743d26f4f6) Merge branch 'main' into fix/org-allowUserToCreateOrganization-typing - [`e22b4da`](https://github.com/better-auth/better-auth/commit/e22b4dae7d29aec6f463f35b7cd79d160f6891de) chore: changeset ### 📊 Changes **2 files changed** (+6 additions, -1 deletions) <details> <summary>View changed files</summary> ➕ `.changeset/silly-falcons-tie.md` (+5 -0) 📝 `packages/better-auth/src/plugins/organization/types.ts` (+1 -1) </details> ### 📄 Description When using the organization plugin and if we have: ```ts allowUserToCreateOrganization(user) { return user.role === "internalAdmin"; }, ``` The user argument does not have `role` in its type definition which led to a type error. It just looks at `schema.ts` and uses the `userSchema` const: ```ts export const userSchema = z.object({ id: z.string(), email: z.string().transform((val) => val.toLowerCase()), emailVerified: z.boolean().default(false), name: z.string(), image: z.string().nullish(), createdAt: z.date().default(() => new Date()), updatedAt: z.date().default(() => new Date()), }); ``` as the type definition. If used in conjuction with the admin plugin I would expect I could get the user's role to check whether it is a regular user or admin. If it is an internal admin role (a custom role) then I would allow organization creation otherwise not. The jwt plugin's `definePayload` method deconstructs a `user` argument which also accepts any fields on the user. ```ts definePayload?: (session: { user: User & Record<string, any>; session: Session & Record<string, any>; }) => Promise<Record<string, any>> | Record<string, any>; ``` Taken inspiration from that, obviously. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Updated the typing for the user argument in allowUserToCreateOrganization to support custom fields like role. <!-- 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-17 21:34:27 -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#30507