[GH-ISSUE #4408] Bug with admin plugin and renamed fields #18553

Closed
opened 2026-04-15 17:03:01 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @maelp on GitHub (Sep 3, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/4408

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

I'm using the admin plugin, which adds a "role" field, I wanted to rename it "better_auth_role", so in the BetterAuth conf I did eg

user: {
modelName: "usersTable",
fields: {
emailVerified: "email_verified",
createdAt: "created_at",
updatedAt: "updated_at",
role: "better_auth_role", // admin plugin
banReason: "ban_reason", // admin plugin
banExpires: "ban_expires", // admin plugin
},
...
but when trying to create a user with auth.api.createUser it complains
The field "role" does not exist in the "usersTable" schema. Please update your drizzle schema or re-generate using "npx @better-auth/cli generate
so it correctly saw that I renamed my table to usersTable (also it works for the other fields like emailVerified, etc) but it seems the admin plugin fields are not translated?

Current vs. Expected behavior

It should use the renamed fields from the config

What version of Better Auth are you using?

latest

System info

latest

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

Backend

Auth config (if applicable)

import { betterAuth } from "better-auth"
export const auth = betterAuth({
  emailAndPassword: {  
    enabled: true
  },
});

Additional context

No response

Originally created by @maelp on GitHub (Sep 3, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/4408 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce I'm using the admin plugin, which adds a "role" field, I wanted to rename it "better_auth_role", so in the BetterAuth conf I did eg user: { modelName: "usersTable", fields: { emailVerified: "email_verified", createdAt: "created_at", updatedAt: "updated_at", role: "better_auth_role", // admin plugin banReason: "ban_reason", // admin plugin banExpires: "ban_expires", // admin plugin }, ... but when trying to create a user with auth.api.createUser it complains The field "role" does not exist in the "usersTable" schema. Please update your drizzle schema or re-generate using "npx @better-auth/cli generate so it correctly saw that I renamed my table to usersTable (also it works for the other fields like emailVerified, etc) but it seems the admin plugin fields are not translated? ### Current vs. Expected behavior It should use the renamed fields from the config ### What version of Better Auth are you using? latest ### System info ```bash latest ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ emailAndPassword: { enabled: true }, }); ``` ### Additional context _No response_
GiteaMirror added the help wantedlocked labels 2026-04-15 17:03:01 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Sep 3, 2025):

This is a known limitation: the admin plugin currently does not fully respect field mappings for renamed fields like role. While your config correctly maps role to better_auth_role, the plugin accesses fields by their logical names, which causes the error when the schema only has the renamed column. Other fields work because the core logic handles mapping, but the admin plugin needs to be updated to use the mapping everywhere it accesses user fields.

As a workaround, you can keep the original field name (role) in your schema, but this defeats the purpose of renaming. If you want to keep using renamed fields, you'll need to ensure both the logical and mapped names exist in your schema, or wait for a future update where the admin plugin fully supports field mapping for all plugin-added fields. This issue has been discussed and is being addressed in ongoing plugin and schema generation work (example).

To reply, just mention @dosu.


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

<!-- gh-comment-id:3250979807 --> @dosubot[bot] commented on GitHub (Sep 3, 2025): <!-- Answer --> This is a known limitation: the admin plugin currently does not fully respect field mappings for renamed fields like `role`. While your config correctly maps `role` to `better_auth_role`, the plugin accesses fields by their logical names, which causes the error when the schema only has the renamed column. Other fields work because the core logic handles mapping, but the admin plugin needs to be updated to use the mapping everywhere it accesses user fields. As a workaround, you can keep the original field name (`role`) in your schema, but this defeats the purpose of renaming. If you want to keep using renamed fields, you'll need to ensure both the logical and mapped names exist in your schema, or wait for a future update where the admin plugin fully supports field mapping for all plugin-added fields. This issue has been discussed and is being addressed in ongoing plugin and schema generation work ([example](https://github.com/better-auth/better-auth/pull/3021)). <!-- 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/ea4cc79b-0117-48e0-9685-6c361f6409a7?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/ea4cc79b-0117-48e0-9685-6c361f6409a7?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/ea4cc79b-0117-48e0-9685-6c361f6409a7?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/ea4cc79b-0117-48e0-9685-6c361f6409a7?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/ea4cc79b-0117-48e0-9685-6c361f6409a7?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/ea4cc79b-0117-48e0-9685-6c361f6409a7?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/ea4cc79b-0117-48e0-9685-6c361f6409a7?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&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/4408)
Author
Owner

@maelp commented on GitHub (Sep 3, 2025):

the error seems to come from here 8466bfe2e4/packages/better-auth/src/adapters/drizzle-adapter/drizzle-adapter.ts (L245)

<!-- gh-comment-id:3250986423 --> @maelp commented on GitHub (Sep 3, 2025): the error seems to come from here https://github.com/better-auth/better-auth/blob/8466bfe2e499f4e594c272ee42b4d6d8bd424147/packages/better-auth/src/adapters/drizzle-adapter/drizzle-adapter.ts#L245
Author
Owner

@ping-maxwell commented on GitHub (Sep 5, 2025):

@maelp I'm going to close this as I assume we solved your issue in the Discord server

<!-- gh-comment-id:3256622512 --> @ping-maxwell commented on GitHub (Sep 5, 2025): @maelp I'm going to close this as I assume we solved your issue in the Discord server
Author
Owner

@maelp commented on GitHub (Sep 5, 2025):

yes all good! perhaps you should add to the doc in either admin plugin, or the general doc mentioning the global schema, that the plugins have to use their own "local schemas" rather than the global one

<!-- gh-comment-id:3257404746 --> @maelp commented on GitHub (Sep 5, 2025): yes all good! perhaps you should add to the doc in either admin plugin, or the general doc mentioning the global schema, that the plugins have to use their own "local schemas" rather than the global one
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#18553