new update v1.3.2 break the admin plugin #1542

Closed
opened 2026-03-13 08:46:49 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @lord007tn on GitHub (Jul 21, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

try adding admin plugin to better-auth and everything will break
even after downgrading to v1.3.1 or v1.3.0 The issue persists

i believe the issue is form

file:///D:/******/node_modules/.pnpm/better-auth@1.3.2_react-dom_ee4f2895fb93365535c9dfcda9c25d49/node_modules/better-auth/dist/shared/better-auth.n2KFGwjY.mjs:162
    for (const field in schema[table].fields) {
                                      ^

TypeError: Cannot read properties of undefined (reading 'fields')
    at mergeSchema (file:///D:/******/node_modules/.pnpm/better-auth@1.3.2_react-dom_ee4f2895fb93365535c9dfcda9c25d49/node_modules/better-auth/dist/shared/better-auth.n2KFGwjY.mjs:162:39)

Current vs. Expected behavior

it should work normally

What version of Better Auth are you using?

1.3.1

Provide environment information

- OS: windows 11
- Node: 22.17.0

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

Package

Auth config (if applicable)

import { betterAuth } from 'better-auth';
import { prismaAdapter } from 'better-auth/adapters/prisma';
import { admin} from 'better-auth/plugins';

export const auth = betterAuth({
  database: prismaAdapter(prisma, {
    provider: 'postgresql',
  }),
  plugins: [
    admin({
      defaultRole: SystemRoles.USER,
      adminRoles: [SystemRoles.ADMIN, SystemRoles.SUPER_ADMIN, SystemRoles.SUPPORT],
      schema: {
        impersonatedBy: 'impersonatorId',
        user: {
          fields: {
            role: 'systemRole',
          },
        },
      },
    }),
  ],
});

Additional context

everything was working before the update 1.3.2
even after trying to use 1.3.1 same issue presist so i belive its the underline packages are requiring v1.3.2 even if I am using v1.3.1

Originally created by @lord007tn on GitHub (Jul 21, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce try adding admin plugin to better-auth and everything will break even after downgrading to v1.3.1 or v1.3.0 The issue persists i believe the issue is form ``` file:///D:/******/node_modules/.pnpm/better-auth@1.3.2_react-dom_ee4f2895fb93365535c9dfcda9c25d49/node_modules/better-auth/dist/shared/better-auth.n2KFGwjY.mjs:162 for (const field in schema[table].fields) { ^ TypeError: Cannot read properties of undefined (reading 'fields') at mergeSchema (file:///D:/******/node_modules/.pnpm/better-auth@1.3.2_react-dom_ee4f2895fb93365535c9dfcda9c25d49/node_modules/better-auth/dist/shared/better-auth.n2KFGwjY.mjs:162:39) ``` ### Current vs. Expected behavior it should work normally ### What version of Better Auth are you using? 1.3.1 ### Provide environment information ```bash - OS: windows 11 - Node: 22.17.0 ``` ### Which area(s) are affected? (Select all that apply) Package ### Auth config (if applicable) ```typescript import { betterAuth } from 'better-auth'; import { prismaAdapter } from 'better-auth/adapters/prisma'; import { admin} from 'better-auth/plugins'; export const auth = betterAuth({ database: prismaAdapter(prisma, { provider: 'postgresql', }), plugins: [ admin({ defaultRole: SystemRoles.USER, adminRoles: [SystemRoles.ADMIN, SystemRoles.SUPER_ADMIN, SystemRoles.SUPPORT], schema: { impersonatedBy: 'impersonatorId', user: { fields: { role: 'systemRole', }, }, }, }), ], }); ``` ### Additional context everything was working before the update 1.3.2 even after trying to use 1.3.1 same issue presist so i belive its the underline packages are requiring v1.3.2 even if I am using v1.3.1
GiteaMirror added the bug label 2026-03-13 08:46:49 -05:00
Author
Owner

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

The error is caused by a mismatch between your admin plugin schema and the structure now required by better-auth after recent updates. The schema passed to the admin plugin must have a top-level object for each table (like user), and each must include a fields property that is itself an object mapping field names to their definitions. If fields is missing or not structured correctly, you'll get the Cannot read properties of undefined (reading 'fields') error.

Your current config:

schema: {
  impersonatedBy: 'impersonatorId',
  user: {
    fields: {
      role: 'systemRole',
    },
  },
}

is missing the required structure. It should look more like:

schema: {
  user: {
    fields: {
      role: { type: "string", required: false }, // adjust as needed
      // ...other fields
    },
  },
  session: {
    fields: {
      impersonatedBy: { type: "string", required: false },
      // ...other fields
    },
  },
}

You can see an example of the expected structure in the admin plugin schema definition.

Recent changes also migrated schema validation to Zod v4 and made schema requirements stricter, so even after downgrading, you may still have mismatched or cached dependencies. To ensure a clean environment: delete node_modules, remove your lockfile (pnpm-lock.yaml or package-lock.json), clear your pnpm cache (pnpm store prune), and reinstall everything.

Once your schema matches the expected structure and your dependencies are reset, the admin plugin should work as expected.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Join Discord Share on X

@dosubot[bot] commented on GitHub (Jul 21, 2025): <!-- Answer --> The error is caused by a mismatch between your admin plugin schema and the structure now required by better-auth after recent updates. The schema passed to the admin plugin must have a top-level object for each table (like `user`), and each must include a `fields` property that is itself an object mapping field names to their definitions. If `fields` is missing or not structured correctly, you'll get the `Cannot read properties of undefined (reading 'fields')` error. Your current config: ```js schema: { impersonatedBy: 'impersonatorId', user: { fields: { role: 'systemRole', }, }, } ``` is missing the required structure. It should look more like: ```js schema: { user: { fields: { role: { type: "string", required: false }, // adjust as needed // ...other fields }, }, session: { fields: { impersonatedBy: { type: "string", required: false }, // ...other fields }, }, } ``` You can see an example of the expected structure in the [admin plugin schema definition](https://github.com/better-auth/better-auth/blob/fa9b4973704f39d7cf7b8c53a7cef8d896209732/packages/better-auth/src/plugins/admin/schema.ts). Recent changes also migrated schema validation to Zod v4 and made schema requirements stricter, so even after downgrading, you may still have mismatched or cached dependencies. To ensure a clean environment: delete `node_modules`, remove your lockfile (`pnpm-lock.yaml` or `package-lock.json`), clear your pnpm cache (`pnpm store prune`), and reinstall everything. Once your schema matches the expected structure and your dependencies are reset, the admin plugin should work as expected. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/b4dbf188-22f4-4919-8f65-0cec00232458?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/b4dbf188-22f4-4919-8f65-0cec00232458?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/b4dbf188-22f4-4919-8f65-0cec00232458?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/b4dbf188-22f4-4919-8f65-0cec00232458?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/b4dbf188-22f4-4919-8f65-0cec00232458?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/b4dbf188-22f4-4919-8f65-0cec00232458?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/b4dbf188-22f4-4919-8f65-0cec00232458?feedback_type=other)</sup>&nbsp;&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/3513)
Author
Owner

@lord007tn commented on GitHub (Jul 21, 2025):

after fixing the session fields everything started and looks good

am closing this

but i believe the types in better auth should be strictier so something like that wont pass

@lord007tn commented on GitHub (Jul 21, 2025): after fixing the session fields everything started and looks good am closing this but i believe the types in better auth should be strictier so something like that wont pass
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1542