[PR #2227] [MERGED] feat: remove the artificial perm limit that code can check #4212

Closed
opened 2026-03-13 11:37:45 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/2227
Author: @rxri
Created: 4/11/2025
Status: Merged
Merged: 4/12/2025
Merged by: @Bekacru

Base: mainHead: feat/limit


📝 Commits (10+)

  • 4d457f7 feat: remove the artificial resource limit so that code can check
  • bc213d5 docs: add examples for multiple perms checking
  • 2094dc7 refactor: check permissions first, then legacy one
  • ec4944d feat: use union types for permission & permissions
  • 0ed3a62 fix: properly use union types
  • 429068b fix: remove accidental @deprecated comment
  • 4f1008e chore: lint
  • 53b0403 fix test
  • d4c03c3 chore: add oneTimeToken plugin to client barrel exports (#2224)
  • 0f3b2ec docs(expo): add id token usage

📊 Changes

15 files changed (+551 additions, -288 deletions)

View changed files

📝 demo/nextjs/lib/auth.ts (+3 -0)
📝 docs/content/docs/plugins/admin.mdx (+40 -13)
📝 docs/content/docs/plugins/organization.mdx (+183 -155)
📝 packages/better-auth/src/plugins/admin/admin.test.ts (+82 -7)
📝 packages/better-auth/src/plugins/admin/admin.ts (+58 -28)
📝 packages/better-auth/src/plugins/admin/client.ts (+26 -14)
📝 packages/better-auth/src/plugins/admin/has-permission.ts (+24 -9)
📝 packages/better-auth/src/plugins/organization/client.ts (+26 -14)
📝 packages/better-auth/src/plugins/organization/has-permission.ts (+23 -8)
📝 packages/better-auth/src/plugins/organization/organization.test.ts (+33 -20)
📝 packages/better-auth/src/plugins/organization/organization.ts (+44 -11)
📝 packages/better-auth/src/plugins/organization/routes/crud-invites.ts (+2 -2)
📝 packages/better-auth/src/plugins/organization/routes/crud-members.ts (+2 -2)
📝 packages/better-auth/src/plugins/organization/routes/crud-org.ts (+2 -2)
📝 packages/better-auth/src/plugins/organization/routes/crud-team.ts (+3 -3)

📄 Description

I noticed that admin and organization plugins have artificial limit of one resource perm at the time, which is super weird because authorize function inside access.ts can check multiple perms from multiple resources at the time.

With this change, I also changed permission to permissions. permission property is left for backwards compatibility. I think it's way better indicator for developer that you can check multiple resources permissions at the time.
The type for permissions is also fixed in this pull request since it had // @ts-expect-error before.


🔄 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/2227 **Author:** [@rxri](https://github.com/rxri) **Created:** 4/11/2025 **Status:** ✅ Merged **Merged:** 4/12/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `main` ← **Head:** `feat/limit` --- ### 📝 Commits (10+) - [`4d457f7`](https://github.com/better-auth/better-auth/commit/4d457f7785603b1c1e9abd9402a0b848007fa43e) feat: remove the artificial resource limit so that code can check - [`bc213d5`](https://github.com/better-auth/better-auth/commit/bc213d53706b6489aa2ed01c8a8f3a03fa042796) docs: add examples for multiple perms checking - [`2094dc7`](https://github.com/better-auth/better-auth/commit/2094dc752a087e1b4000d15fb66f41c11ea4dd50) refactor: check `permissions` first, then legacy one - [`ec4944d`](https://github.com/better-auth/better-auth/commit/ec4944ddf84754bd91752f16d2dd7fc884ae4322) feat: use union types for `permission` & `permissions` - [`0ed3a62`](https://github.com/better-auth/better-auth/commit/0ed3a62ea8eff1080ec66918f4582ed43da5c344) fix: properly use union types - [`429068b`](https://github.com/better-auth/better-auth/commit/429068b8b7757541800af8a155f141d5a4d421a8) fix: remove accidental `@deprecated` comment - [`4f1008e`](https://github.com/better-auth/better-auth/commit/4f1008e76f96e880ace093a15a2d58041daeb59d) chore: lint - [`53b0403`](https://github.com/better-auth/better-auth/commit/53b0403635ab11c5ee65af659b0b767f5e6efc22) fix test - [`d4c03c3`](https://github.com/better-auth/better-auth/commit/d4c03c38f6ba320eab570a8bd511be2a3087f785) chore: add oneTimeToken plugin to client barrel exports (#2224) - [`0f3b2ec`](https://github.com/better-auth/better-auth/commit/0f3b2ec74f07590b99b556f7ce83a80068b58164) docs(expo): add id token usage ### 📊 Changes **15 files changed** (+551 additions, -288 deletions) <details> <summary>View changed files</summary> 📝 `demo/nextjs/lib/auth.ts` (+3 -0) 📝 `docs/content/docs/plugins/admin.mdx` (+40 -13) 📝 `docs/content/docs/plugins/organization.mdx` (+183 -155) 📝 `packages/better-auth/src/plugins/admin/admin.test.ts` (+82 -7) 📝 `packages/better-auth/src/plugins/admin/admin.ts` (+58 -28) 📝 `packages/better-auth/src/plugins/admin/client.ts` (+26 -14) 📝 `packages/better-auth/src/plugins/admin/has-permission.ts` (+24 -9) 📝 `packages/better-auth/src/plugins/organization/client.ts` (+26 -14) 📝 `packages/better-auth/src/plugins/organization/has-permission.ts` (+23 -8) 📝 `packages/better-auth/src/plugins/organization/organization.test.ts` (+33 -20) 📝 `packages/better-auth/src/plugins/organization/organization.ts` (+44 -11) 📝 `packages/better-auth/src/plugins/organization/routes/crud-invites.ts` (+2 -2) 📝 `packages/better-auth/src/plugins/organization/routes/crud-members.ts` (+2 -2) 📝 `packages/better-auth/src/plugins/organization/routes/crud-org.ts` (+2 -2) 📝 `packages/better-auth/src/plugins/organization/routes/crud-team.ts` (+3 -3) </details> ### 📄 Description I noticed that [`admin`](https://github.com/better-auth/better-auth/tree/main/packages/better-auth/src/plugins/admin) and [`organization`](https://github.com/better-auth/better-auth/tree/main/packages/better-auth/src/plugins/organization) plugins have artificial limit of one resource perm at the time, which is super weird because [`authorize`](https://github.com/better-auth/better-auth/blob/main/packages/better-auth/src/plugins/access/access.ts#L10) function inside [`access.ts`](https://github.com/better-auth/better-auth/blob/main/packages/better-auth/src/plugins/access/access.ts) can check multiple perms from multiple resources at the time. With this change, I also changed `permission` to `permissions`. `permission` property is left for backwards compatibility. I think it's way better indicator for developer that you can check multiple resources permissions at the time. The type for `permissions` is also fixed in this pull request since it had `// @ts-expect-error` before. --- <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-03-13 11:37:45 -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#4212