a request to check email on registration hardcode a table "user" instead of using the define table name #1634

Closed
opened 2026-03-13 08:52:39 -05:00 by GiteaMirror · 9 comments
Owner

Originally created by @lanfeust21 on GitHub (Aug 4, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Here's a comprehensive bug report for the Better Auth hardcoded "user" table issue:


Bug Report: Better Auth Hardcodes "user" Table Name Instead of Using Configuration

Issue Summary

Better Auth ignores the tables configuration and hardcodes "user" as the table name in its internal code, causing database connection errors when the actual table name is different (e.g., "users").

Environment

  • Better Auth Version: 1.3.4 (latest)
  • Database: PostgreSQL
  • Expected Table: "<schema>"."users"
  • Better Auth Tries: "user" (hardcoded)

Error Details

error: relation "user" does not exist
STATEMENT: select * from "user" where "email" = $1

Root Cause

The issue is in Better Auth's internal code at:

node_modules/.pnpm/better-auth@1.3.4/node_modules/better-auth/dist/shared/better-auth.ByruPN9q.mjs

Lines 164-165:

createUser: async (user, context) => {
  const createdUser = await createWithHooks(
    {
      createdAt: /* @__PURE__ */ new Date(),
      updatedAt: /* @__PURE__ */ new Date(),
      emailVerified: false,
      ...user,
      email: user.email?.toLowerCase()
    },
    "user",  // ← HARDCODED TABLE NAME
    void 0,
    context
  );
  return createdUser;
},

Configuration Attempted

export const auth = betterAuth({
  database: pool,
  plugins: [jwt(), bearer()],
  tables: {
    user: "\"<schema>\".\"users\"",  // ← This should work but doesn't
    session: "\"<schema>\".\"sessions\"", 
    account: "\"<schema>\".\"accounts\"",
    verificationToken: "\"<schema>\".\"verificationTokens\""
  },
  fieldMappings: {
    user: {
      "createdAt": "created_at",
      "updatedAt": "updated_at"
    },
    // ... other mappings
  },
  // ... rest of config
});

Expected Behavior

Better Auth should use the configured table name "<schema>"."users" instead of the hardcoded "user".

Actual Behavior

Better Auth ignores the tables.user configuration and always uses the hardcoded string "user".

Impact

  • Prevents Better Auth from working with existing database schemas
  • Forces users to create views or rename tables to match Better Auth's expectations
  • Breaks the promise of configurable table names

Workarounds Attempted

  1. PostgreSQL View: Created CREATE VIEW "user" AS SELECT * FROM "<schema>"."users"
  2. Column Mapping: Added field mappings for camelCase/snake_case conversion
  3. Schema Prefixing: Used fully qualified table names with schema

Reproduction Steps

  1. Set up Better Auth with custom table names in tables configuration
  2. Ensure actual database table is named differently (e.g., users instead of user)
  3. Attempt any Better Auth operation (sign-up, sign-in, etc.)
  4. Observe database error about missing "user" table

Code Evidence

# Search for hardcoded "user" in Better Auth source
grep -n "user" node_modules/.pnpm/better-auth@1.3.4/node_modules/better-auth/dist/shared/better-auth.ByruPN9q.mjs

# Result shows multiple hardcoded instances:
164:        "user",

Suggested Fix

Better Auth should:

  1. Read the tables.user configuration
  2. Use the configured table name instead of hardcoding "user"
  3. Apply the same logic to other table types (session, account, etc.)

Priority

High - This is a fundamental configuration issue that breaks Better Auth's core promise of database flexibility.


This bug report provides all the technical details needed for the Better Auth maintainers to understand and fix the issue.

Current vs. Expected behavior

i expected to use the tables definition aka tables.user

export const auth = betterAuth({
	database: pool,
	plugins: [jwt(), bearer()],
	tables: {
		user: "\"<schema>\".\"users\"",
		session: "\"<schema>\".\"sessions\"", 
		account: "\"<schema>\".\"accounts\"",
		verificationToken: "\<schema>\".\"verificationTokens\""
	},
....

on the postgres logs
select * from "user" where "email" = $1
2025-08-04 08:36:32.866 UTC [530] ERROR: relation "user" does not exist at character 15

What version of Better Auth are you using?

1.3.4

Provide environment information

-OS: linux Mint
- svelte5/sveltekit integration

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

Backend

Auth config (if applicable)

export const auth = betterAuth({
	database: pool,
	plugins: [jwt(), bearer()],
	tables: {
		user: "\"<schema>\".\"users\"",
		session: "\"<schema>\".\"sessions\"", 
		account: "\"<schema>\".\"accounts\"",
		verificationToken: "\<schema>\".\"verificationTokens\""
	},
....

Additional context

already explained

Originally created by @lanfeust21 on GitHub (Aug 4, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce Here's a comprehensive bug report for the Better Auth hardcoded "user" table issue: --- ## Bug Report: Better Auth Hardcodes "user" Table Name Instead of Using Configuration ### Issue Summary Better Auth ignores the `tables` configuration and hardcodes `"user"` as the table name in its internal code, causing database connection errors when the actual table name is different (e.g., `"users"`). ### Environment - **Better Auth Version**: 1.3.4 (latest) - **Database**: PostgreSQL - **Expected Table**: `"<schema>"."users"` - **Better Auth Tries**: `"user"` (hardcoded) ### Error Details ``` error: relation "user" does not exist STATEMENT: select * from "user" where "email" = $1 ``` ### Root Cause The issue is in Better Auth's internal code at: ``` node_modules/.pnpm/better-auth@1.3.4/node_modules/better-auth/dist/shared/better-auth.ByruPN9q.mjs ``` **Lines 164-165:** ```javascript createUser: async (user, context) => { const createdUser = await createWithHooks( { createdAt: /* @__PURE__ */ new Date(), updatedAt: /* @__PURE__ */ new Date(), emailVerified: false, ...user, email: user.email?.toLowerCase() }, "user", // ← HARDCODED TABLE NAME void 0, context ); return createdUser; }, ``` ### Configuration Attempted ```typescript export const auth = betterAuth({ database: pool, plugins: [jwt(), bearer()], tables: { user: "\"<schema>\".\"users\"", // ← This should work but doesn't session: "\"<schema>\".\"sessions\"", account: "\"<schema>\".\"accounts\"", verificationToken: "\"<schema>\".\"verificationTokens\"" }, fieldMappings: { user: { "createdAt": "created_at", "updatedAt": "updated_at" }, // ... other mappings }, // ... rest of config }); ``` ### Expected Behavior Better Auth should use the configured table name `"<schema>"."users"` instead of the hardcoded `"user"`. ### Actual Behavior Better Auth ignores the `tables.user` configuration and always uses the hardcoded string `"user"`. ### Impact - Prevents Better Auth from working with existing database schemas - Forces users to create views or rename tables to match Better Auth's expectations - Breaks the promise of configurable table names ### Workarounds Attempted 1. **PostgreSQL View**: Created `CREATE VIEW "user" AS SELECT * FROM "<schema>"."users"` 2. **Column Mapping**: Added field mappings for camelCase/snake_case conversion 3. **Schema Prefixing**: Used fully qualified table names with schema ### Reproduction Steps 1. Set up Better Auth with custom table names in `tables` configuration 2. Ensure actual database table is named differently (e.g., `users` instead of `user`) 3. Attempt any Better Auth operation (sign-up, sign-in, etc.) 4. Observe database error about missing `"user"` table ### Code Evidence ```bash # Search for hardcoded "user" in Better Auth source grep -n "user" node_modules/.pnpm/better-auth@1.3.4/node_modules/better-auth/dist/shared/better-auth.ByruPN9q.mjs # Result shows multiple hardcoded instances: 164: "user", ``` ### Suggested Fix Better Auth should: 1. Read the `tables.user` configuration 2. Use the configured table name instead of hardcoding `"user"` 3. Apply the same logic to other table types (`session`, `account`, etc.) ### Priority **High** - This is a fundamental configuration issue that breaks Better Auth's core promise of database flexibility. --- This bug report provides all the technical details needed for the Better Auth maintainers to understand and fix the issue. ### Current vs. Expected behavior i expected to use the tables definition aka tables.user ``` export const auth = betterAuth({ database: pool, plugins: [jwt(), bearer()], tables: { user: "\"<schema>\".\"users\"", session: "\"<schema>\".\"sessions\"", account: "\"<schema>\".\"accounts\"", verificationToken: "\<schema>\".\"verificationTokens\"" }, .... ``` on the postgres logs select * from "user" where "email" = $1 2025-08-04 08:36:32.866 UTC [530] ERROR: relation "user" does not exist at character 15 ### What version of Better Auth are you using? 1.3.4 ### Provide environment information ```bash -OS: linux Mint - svelte5/sveltekit integration ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript export const auth = betterAuth({ database: pool, plugins: [jwt(), bearer()], tables: { user: "\"<schema>\".\"users\"", session: "\"<schema>\".\"sessions\"", account: "\"<schema>\".\"accounts\"", verificationToken: "\<schema>\".\"verificationTokens\"" }, .... ``` ### Additional context already explained
GiteaMirror added the bug label 2026-03-13 08:52:39 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Aug 4, 2025):

Hi @lanfeust21! I'm Dosu and I’m helping the better-auth team.

This is a known issue in Better Auth: the table name "user" is hardcoded in several places, so the tables.user or modelName configuration is ignored in some flows. This causes errors when your actual table is named differently (like "users" or with a schema prefix), and has been reported by others as well (#2307, #2709, #2713, #3069, #1027). The maintainers have acknowledged the problem and are incrementally fixing similar bugs for other models (see the recent rateLimit fix), but as of now, the "user" table hardcoding remains unfixed.

Workarounds include creating a view named "user" in your database, ensuring your config uses modelName: "users" if your table is plural, and enabling the usePlural flag if you use plural table names (docs). These are not always ideal, but may help until the core issue is fixed.

If you need to support a custom table name for users, keep an eye on related issues and changelogs for a permanent fix.

To reply, just mention @dosu.


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

@dosubot[bot] commented on GitHub (Aug 4, 2025): <!-- Greeting --> Hi @lanfeust21! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> This is a known issue in Better Auth: the table name `"user"` is hardcoded in several places, so the `tables.user` or `modelName` configuration is ignored in some flows. This causes errors when your actual table is named differently (like `"users"` or with a schema prefix), and has been reported by others as well ([#2307](https://github.com/better-auth/better-auth/issues/2307), [#2709](https://github.com/better-auth/better-auth/issues/2709), [#2713](https://github.com/better-auth/better-auth/issues/2713), [#3069](https://github.com/better-auth/better-auth/issues/3069), [#1027](https://github.com/better-auth/better-auth/issues/1027)). The maintainers have acknowledged the problem and are incrementally fixing similar bugs for other models (see the recent [rateLimit fix](https://github.com/better-auth/better-auth/pull/3536)), but as of now, the `"user"` table hardcoding remains unfixed. Workarounds include creating a view named `"user"` in your database, ensuring your config uses `modelName: "users"` if your table is plural, and enabling the `usePlural` flag if you use plural table names ([docs](https://www.better-auth.com/docs/concepts/database#custom-table-names)). These are not always ideal, but may help until the core issue is fixed. If you need to support a custom table name for users, keep an eye on related issues and changelogs for a permanent fix. <!-- 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/c8602b4c-9a0f-41a8-9f42-aaa3ee20d6db?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/c8602b4c-9a0f-41a8-9f42-aaa3ee20d6db?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/c8602b4c-9a0f-41a8-9f42-aaa3ee20d6db?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/c8602b4c-9a0f-41a8-9f42-aaa3ee20d6db?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/c8602b4c-9a0f-41a8-9f42-aaa3ee20d6db?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/c8602b4c-9a0f-41a8-9f42-aaa3ee20d6db?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/c8602b4c-9a0f-41a8-9f42-aaa3ee20d6db?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/3774)
Author
Owner

@mariusa commented on GitHub (Oct 6, 2025):

Why close the issue? Close when fixed. @Kinfe123

@mariusa commented on GitHub (Oct 6, 2025): Why close the issue? Close when fixed. @Kinfe123
Author
Owner

@angelorc commented on GitHub (Oct 21, 2025):

Any update? Would be awesome to use a table prefix

@angelorc commented on GitHub (Oct 21, 2025): Any update? Would be awesome to use a table prefix
Author
Owner

@marcospgp commented on GitHub (Nov 14, 2025):

@Kinfe123 can you please reopen this? was about to rename betterauth tables but claude warned me against it because of this issue specifically

@marcospgp commented on GitHub (Nov 14, 2025): @Kinfe123 can you please reopen this? was about to rename betterauth tables but claude warned me against it because of this issue specifically
Author
Owner

@aditya-shindee commented on GitHub (Nov 26, 2025):

export const auth = betterAuth({
    user: {
      modelName: "users", // Custom table name
    },

is it ok? if we do this

@aditya-shindee commented on GitHub (Nov 26, 2025): ``` export const auth = betterAuth({ user: { modelName: "users", // Custom table name }, ``` is it ok? if we do this
Author
Owner

@ianatek commented on GitHub (Dec 17, 2025):

export const auth = betterAuth({
    user: {
      modelName: "users", // Custom table name
    },

is it ok? if we do this

Not for me

@ianatek commented on GitHub (Dec 17, 2025): > ``` > export const auth = betterAuth({ > user: { > modelName: "users", // Custom table name > }, > ``` > > is it ok? if we do this Not for me
Author
Owner

@sud33p commented on GitHub (Jan 26, 2026):

Agree, this bug needs to be addressed properly. I was also about to add prefix to the betterauth tables and Claude code warned me and sent me here. Prefixing table names based on feature/app is a common usecase.

@sud33p commented on GitHub (Jan 26, 2026): Agree, this bug needs to be addressed properly. I was also about to add prefix to the betterauth tables and Claude code warned me and sent me here. Prefixing table names based on feature/app is a common usecase.
Author
Owner

@darlenya commented on GitHub (Feb 5, 2026):

Same for me. To bring some order in the tables in my schema all the tables are prefixed for a reason.

@darlenya commented on GitHub (Feb 5, 2026): Same for me. To bring some order in the tables in my schema all the tables are prefixed for a reason.
Author
Owner

@lubiah commented on GitHub (Feb 10, 2026):

This is really a blocker. and the issue is closed too.

@lubiah commented on GitHub (Feb 10, 2026): This is really a blocker. and the issue is closed too.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1634