[GH-ISSUE #2696] [bug] Organization plugin | TypeError: Cannot read properties of undefined (reading 'roles') #17938

Closed
opened 2026-04-15 16:18:03 -05:00 by GiteaMirror · 0 comments
Owner

Originally created by @tomquirk on GitHub (May 18, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/2696

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Use organization plugin with no option argument (e.g. plugins: [ organization() ])
  2. Create an organization
  3. Execute hasPermission
  await auth.api.hasPermission({
    headers: await headers(),
    body: {
      permissions: {
        invitation: ["create"], // This must match the structure in your access control
      },
    },
  });
  1. Observe logs:

TypeError: Cannot read properties of undefined (reading 'roles')

Current vs. Expected behavior

Current: the error
Expected: hasPermission should work as expected, regardless of if user has specified options in organization plugin or not.

What version of Better Auth are you using?

1.2.8

Provide environment information

- MacOS, Brave

Which area(s) are affected? (Select all that apply)

Backend

Auth config (if applicable)

export const auth = betterAuth({
  plugins: [organization()]
})

Additional context

If an empty object is passed in to organization plugin, the error is resolved:

export const auth = betterAuth({
  plugins: [organization({})] // pass empty object as opt
})
Originally created by @tomquirk on GitHub (May 18, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/2696 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Use organization plugin _with no option argument_ (e.g. `plugins: [ organization() ]`) 2. Create an organization 3. Execute hasPermission ```ts await auth.api.hasPermission({ headers: await headers(), body: { permissions: { invitation: ["create"], // This must match the structure in your access control }, }, }); ``` 4. Observe logs: > TypeError: Cannot read properties of undefined (reading 'roles') ### Current vs. Expected behavior Current: the error Expected: hasPermission should work as expected, regardless of if user has specified options in `organization` plugin or not. ### What version of Better Auth are you using? 1.2.8 ### Provide environment information ```bash - MacOS, Brave ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript export const auth = betterAuth({ plugins: [organization()] }) ``` ### Additional context If an empty object is passed in to `organization` plugin, the error is resolved: ```ts export const auth = betterAuth({ plugins: [organization({})] // pass empty object as opt }) ```
GiteaMirror added the locked label 2026-04-15 16:18:03 -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#17938