[GH-ISSUE #8779] Renamed Fields are not recognising #28512

Open
opened 2026-04-17 19:58:02 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @iamharidasan on GitHub (Mar 26, 2026).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/8779

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

If we rename the ID fields, then the user creation (signUpEmail) fails. As we work on a complex project, we need to maintain user_id instead of id on the user model, session_id instead of id on the session model, and so on.

auth.js:

user: {
    modelName: "users",
    fields: {
      id: "user_id", 
      emailVerified: "email_verified",
      createdAt: "created_at",
      updatedAt: "updated_at",
    },
  }
INFO [Better Auth]: [Prisma Adapter] #2 [3/4] create (DB Result): {
  model: 'users',
  res: {
    user_id: 1,
    name: 'Haridasan',
    email: 'haridasan@test.tech',
    email_verified: false,
    image: null,
    created_at: 2026-03-26T02:38:24.094Z,
    updated_at: 2026-03-26T02:38:24.094Z,
    role: 'user',
    banned: false,
    banReason: null,
    banExpires: null
  }
}

Under the parsed result, the ID returns as null

INFO [Better Auth]: [Prisma Adapter] #2 [4/4] create (Parsed Result): {
  model: 'users',
  data: {
    name: 'Haridasan',
    email: 'haridasan@test.tech',
    emailVerified: false,
    image: null,
    createdAt: 2026-03-26T02:38:24.094Z,
    updatedAt: 2026-03-26T02:38:24.094Z,
    role: 'user',
    banned: false,
    banReason: null,
    banExpires: null,
    id: undefined
  }
}

Current vs. Expected behavior

Currently, id returns empty after renaming them via auth.ts. Due to this, the accountId has a null value, and user creation fails.

INFO [Better Auth]: [Prisma Adapter] #2 [4/4] create (Parsed Result): {
  model: 'users',
  data: {
    name: 'Haridasan',
    email: 'haridasan@test.tech',
    emailVerified: false,
    image: null,
    createdAt: 2026-03-26T02:38:24.094Z,
    updatedAt: 2026-03-26T02:38:24.094Z,
    role: 'user',
    banned: false,
    banReason: null,
    banExpires: null,
    id: undefined
  }
}
INFO [Better Auth]: [Prisma Adapter] #3 [1/4] create (Unsafe Input): {
  model: 'account',
  data: {
    createdAt: 2026-03-26T02:38:24.124Z,
    updatedAt: 2026-03-26T02:38:24.124Z,
    userId: undefined,
    providerId: 'credential',
    accountId: undefined,
    password: '6127f4255f9b535aaebea02c61fb59eb:34120393302d537a939ac2a26e988413347e5837ba1954f6ea5bda7f54f125394070a5b2a0ece5e2e94d2cf4217159f73aee6af80dee4bdf0fe0b65f2401e761'
  }
}

Expected:

INFO [Better Auth]: [Prisma Adapter] #2 [4/4] create (Parsed Result): {
  model: 'users',
  data: {
    name: 'Haridasan',
    email: 'haridasan@test.tech',
    emailVerified: false,
    image: null,
    createdAt: 2026-03-26T02:38:24.094Z,
    updatedAt: 2026-03-26T02:38:24.094Z,
    role: 'user',
    banned: false,
    banReason: null,
    banExpires: null,
    id: 1
  }
}
INFO [Better Auth]: [Prisma Adapter] #3 [1/4] create (Unsafe Input): {
  model: 'account',
  data: {
    createdAt: 2026-03-26T02:38:24.124Z,
    updatedAt: 2026-03-26T02:38:24.124Z,
    userId: undefined,
    providerId: 'credential',
    accountId: '1',
    password: '6127f4255f9b535aaebea02c61fb59eb:34120393302d537a939ac2a26e988413347e5837ba1954f6ea5bda7f54f125394070a5b2a0ece5e2e94d2cf4217159f73aee6af80dee4bdf0fe0b65f2401e761'
  }
}

What version of Better Auth are you using?

1.5.6

System info

{
  "system": {
    "platform": "win32",
    "arch": "x64",
    "version": "Windows 11 Home Single Language",
    "release": "10.0.26200",
    "cpuCount": 16,
    "cpuModel": "AMD Ryzen 7 5800H with Radeon Graphics",
    "totalMemory": "15.40 GB",
    "freeMemory": "2.50 GB"
  },
  "node": {
    "version": "v24.11.1",
    "env": "development"
  },
  "packageManager": {
    "name": "npm",
    "version": "11.7.0"
  },
  "frameworks": [
    {
      "name": "next",
      "version": "16.1.6"
    },
    {
      "name": "react",
      "version": "19.2.3"
    }
  ],
  "databases": [
    {
      "name": "pg",
      "version": "^8.20.0"
    },
    {
      "name": "@prisma/client",
      "version": "^7.5.0"
    }
  ],
  "betterAuth": {
    "version": "^1.5.4",
    "config": {
      "baseURL": "http://localhost:3000/",
      "emailAndPassword": {
        "enabled": true
      },
      "advanced": {
        "database": {
          "generateId": "serial"
        }
      },
      "plugins": [
        {
          "name": "admin",
          "config": {
            "id": "admin",
            "hooks": {
              "after": [
                {}
              ]
            },
            "endpoints": {},
            "$ERROR_CODES": {
              "FAILED_TO_CREATE_USER": {
                "code": "FAILED_TO_CREATE_USER",
                "message": "Failed to create user"
              },
              "USER_ALREADY_EXISTS": {
                "code": "USER_ALREADY_EXISTS",
                "message": "User already exists."
              },
              "USER_ALREADY_EXISTS_USE_ANOTHER_EMAIL": {
                "code": "USER_ALREADY_EXISTS_USE_ANOTHER_EMAIL",
                "message": "User already exists. Use another email."
              },
              "YOU_CANNOT_BAN_YOURSELF": {
                "code": "YOU_CANNOT_BAN_YOURSELF",
                "message": "You cannot ban yourself"
              },
              "YOU_ARE_NOT_ALLOWED_TO_CHANGE_USERS_ROLE": {
                "code": "YOU_ARE_NOT_ALLOWED_TO_CHANGE_USERS_ROLE",
                "message": "You are not allowed to change users role"
              },
              "YOU_ARE_NOT_ALLOWED_TO_CREATE_USERS": {
                "code": "YOU_ARE_NOT_ALLOWED_TO_CREATE_USERS",
                "message": "You are not allowed to create users"
              },
              "YOU_ARE_NOT_ALLOWED_TO_LIST_USERS": {
                "code": "YOU_ARE_NOT_ALLOWED_TO_LIST_USERS",
                "message": "You are not allowed to list users"
              },
              "YOU_ARE_NOT_ALLOWED_TO_LIST_USERS_SESSIONS": {
                "code": "YOU_ARE_NOT_ALLOWED_TO_LIST_USERS_SESSIONS",
                "message": "You are not allowed to list users sessions"
              },
              "YOU_ARE_NOT_ALLOWED_TO_BAN_USERS": {
                "code": "YOU_ARE_NOT_ALLOWED_TO_BAN_USERS",
                "message": "You are not allowed to ban users"
              },
              "YOU_ARE_NOT_ALLOWED_TO_IMPERSONATE_USERS": {
                "code": "YOU_ARE_NOT_ALLOWED_TO_IMPERSONATE_USERS",
                "message": "You are not allowed to impersonate users"
              },
              "YOU_ARE_NOT_ALLOWED_TO_REVOKE_USERS_SESSIONS": {
                "code": "YOU_ARE_NOT_ALLOWED_TO_REVOKE_USERS_SESSIONS",
                "message": "You are not allowed to revoke users sessions"
              },
              "YOU_ARE_NOT_ALLOWED_TO_DELETE_USERS": {
                "code": "YOU_ARE_NOT_ALLOWED_TO_DELETE_USERS",
                "message": "You are not allowed to delete users"
              },
              "YOU_ARE_NOT_ALLOWED_TO_SET_USERS_PASSWORD": {
                "code": "YOU_ARE_NOT_ALLOWED_TO_SET_USERS_PASSWORD",
                "message": "You are not allowed to set users password"
              },
              "BANNED_USER": {
                "code": "BANNED_USER",
                "message": "You have been banned from this application"
              },
              "YOU_ARE_NOT_ALLOWED_TO_GET_USER": {
                "code": "YOU_ARE_NOT_ALLOWED_TO_GET_USER",
                "message": "You are not allowed to get user"
              },
              "NO_DATA_TO_UPDATE": {
                "code": "NO_DATA_TO_UPDATE",
                "message": "No data to update"
              },
              "YOU_ARE_NOT_ALLOWED_TO_UPDATE_USERS": {
                "code": "YOU_ARE_NOT_ALLOWED_TO_UPDATE_USERS",
                "message": "You are not allowed to update users"
              },
              "YOU_CANNOT_REMOVE_YOURSELF": {
                "code": "YOU_CANNOT_REMOVE_YOURSELF",
                "message": "You cannot remove yourself"
              },
              "YOU_ARE_NOT_ALLOWED_TO_SET_NON_EXISTENT_VALUE": {
                "code": "YOU_ARE_NOT_ALLOWED_TO_SET_NON_EXISTENT_VALUE",
                "message": "You are not allowed to set a non-existent role value"
              },
              "YOU_CANNOT_IMPERSONATE_ADMINS": {
                "code": "YOU_CANNOT_IMPERSONATE_ADMINS",
                "message": "You cannot impersonate admins"
              },
              "INVALID_ROLE_TYPE": {
                "code": "INVALID_ROLE_TYPE",
                "message": "Invalid role type"
              }
            },
            "schema": {
              "user": {
                "fields": {
                  "role": {
                    "type": "string",
                    "required": false,
                    "input": false
                  },
                  "banned": {
                    "type": "boolean",
                    "defaultValue": false,
                    "required": false,
                    "input": false
                  },
                  "banReason": {
                    "type": "string",
                    "required": false,
                    "input": false
                  },
                  "banExpires": {
                    "type": "date",
                    "required": false,
                    "input": false
                  }
                }
              },
              "session": {
                "fields": {
                  "impersonatedBy": {
                    "type": "string",
                    "required": false
                  }
                }
              }
            }
          }
        }
      ],
      "user": {
        "modelName": "users",
        "fields": {
          "id": "user_id",
          "emailVerified": "email_verified",
          "createdAt": "created_at",
          "updatedAt": "updated_at"
        }
      },
      "session": {
        "fields": {
          "id": "session_id",
          "userId": "user_id",
          "expiresAt": "expires_at",
          "ipAddress": "ip_address",
          "userAgent": "user_agent",
          "createdAt": "created_at",
          "updatedAt": "updated_at"
        }
      },
      "account": {
        "fields": {
          "accountId": "account_id",
          "userId": "user_id",
          "providerId": "provider_id",
          "accessToken": "[REDACTED]",
          "refreshToken": "[REDACTED]",
          "accessTokenExpiresAt": "access_token_expires_at",
          "refreshTokenExpiresAt": "refresh_token_expires_at",
          "idToken": "[REDACTED]",
          "createdAt": "created_at",
          "updatedAt": "updated_at"
        }
      },
      "verification": {
        "fields": {
          "expiresAt": "expires_at",
          "createdAt": "created_at",
          "updatedAt": "updated_at"
        }
      }
    }
  }
}

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

Other, Client

Auth config (if applicable)

import "dotenv/config";
import { PrismaPg } from "@prisma/adapter-pg";
import { PrismaClient } from "@/generated/prisma/client";
import { betterAuth } from "better-auth";
import { prismaAdapter } from "better-auth/adapters/prisma";
import { admin } from "better-auth/plugins";

const adapter = new PrismaPg({
  connectionString: process.env.DATABASE_URL,
  connectionTimeoutMillis: 10000,
  idleTimeoutMillis: 10000,
  maxLifetimeSeconds: 30,
  max: 100,
});

const client = new PrismaClient({ adapter });

export const auth = betterAuth({
  database: prismaAdapter(client, { provider: "postgresql", debugLogs: true }),
  baseURL: "http://localhost:3000/",
  emailAndPassword: { enabled: true },
  advanced: {
    database: {
      generateId: "serial",
    },
  },
  plugins: [admin()],
  user: {
    modelName: "users",
    fields: {
      id: "user_id",
      emailVerified: "email_verified",
      createdAt: "created_at",
      updatedAt: "updated_at",
    },
  },
  session: {
    fields: {
      id: "session_id",
      userId: "user_id",
      expiresAt: "expires_at",
      ipAddress: "ip_address",
      userAgent: "user_agent",
      createdAt: "created_at",
      updatedAt: "updated_at",
    },
  },
  account: {
    fields: {
      accountId: "account_id",
      userId: "user_id",
      providerId: "provider_id",
      accessToken: "access_token",
      refreshToken: "refresh_token",
      accessTokenExpiresAt: "access_token_expires_at",
      refreshTokenExpiresAt: "refresh_token_expires_at",
      idToken: "id_token",
      createdAt: "created_at",
      updatedAt: "updated_at",
    },
  },
  verification: {
    fields: {
      expiresAt: "expires_at",
      createdAt: "created_at",
      updatedAt: "updated_at",
    },
  },
});

Additional context

I have been stuck at this for the last 2 days. Kindly help me solve this issue at earliest

Originally created by @iamharidasan on GitHub (Mar 26, 2026). Original GitHub issue: https://github.com/better-auth/better-auth/issues/8779 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce If we rename the ID fields, then the user creation (signUpEmail) fails. As we work on a complex project, we need to maintain user_id instead of id on the user model, session_id instead of id on the session model, and so on. auth.js: ``` user: { modelName: "users", fields: { id: "user_id", emailVerified: "email_verified", createdAt: "created_at", updatedAt: "updated_at", }, } ``` ``` INFO [Better Auth]: [Prisma Adapter] #2 [3/4] create (DB Result): { model: 'users', res: { user_id: 1, name: 'Haridasan', email: 'haridasan@test.tech', email_verified: false, image: null, created_at: 2026-03-26T02:38:24.094Z, updated_at: 2026-03-26T02:38:24.094Z, role: 'user', banned: false, banReason: null, banExpires: null } } ``` Under the parsed result, the ID returns as null ``` INFO [Better Auth]: [Prisma Adapter] #2 [4/4] create (Parsed Result): { model: 'users', data: { name: 'Haridasan', email: 'haridasan@test.tech', emailVerified: false, image: null, createdAt: 2026-03-26T02:38:24.094Z, updatedAt: 2026-03-26T02:38:24.094Z, role: 'user', banned: false, banReason: null, banExpires: null, id: undefined } } ``` ### Current vs. Expected behavior Currently, id returns empty after renaming them via auth.ts. Due to this, the accountId has a null value, and user creation fails. ``` INFO [Better Auth]: [Prisma Adapter] #2 [4/4] create (Parsed Result): { model: 'users', data: { name: 'Haridasan', email: 'haridasan@test.tech', emailVerified: false, image: null, createdAt: 2026-03-26T02:38:24.094Z, updatedAt: 2026-03-26T02:38:24.094Z, role: 'user', banned: false, banReason: null, banExpires: null, id: undefined } } ``` ``` INFO [Better Auth]: [Prisma Adapter] #3 [1/4] create (Unsafe Input): { model: 'account', data: { createdAt: 2026-03-26T02:38:24.124Z, updatedAt: 2026-03-26T02:38:24.124Z, userId: undefined, providerId: 'credential', accountId: undefined, password: '6127f4255f9b535aaebea02c61fb59eb:34120393302d537a939ac2a26e988413347e5837ba1954f6ea5bda7f54f125394070a5b2a0ece5e2e94d2cf4217159f73aee6af80dee4bdf0fe0b65f2401e761' } } ``` Expected: ``` INFO [Better Auth]: [Prisma Adapter] #2 [4/4] create (Parsed Result): { model: 'users', data: { name: 'Haridasan', email: 'haridasan@test.tech', emailVerified: false, image: null, createdAt: 2026-03-26T02:38:24.094Z, updatedAt: 2026-03-26T02:38:24.094Z, role: 'user', banned: false, banReason: null, banExpires: null, id: 1 } } ``` ``` INFO [Better Auth]: [Prisma Adapter] #3 [1/4] create (Unsafe Input): { model: 'account', data: { createdAt: 2026-03-26T02:38:24.124Z, updatedAt: 2026-03-26T02:38:24.124Z, userId: undefined, providerId: 'credential', accountId: '1', password: '6127f4255f9b535aaebea02c61fb59eb:34120393302d537a939ac2a26e988413347e5837ba1954f6ea5bda7f54f125394070a5b2a0ece5e2e94d2cf4217159f73aee6af80dee4bdf0fe0b65f2401e761' } } ``` ### What version of Better Auth are you using? 1.5.6 ### System info ```bash { "system": { "platform": "win32", "arch": "x64", "version": "Windows 11 Home Single Language", "release": "10.0.26200", "cpuCount": 16, "cpuModel": "AMD Ryzen 7 5800H with Radeon Graphics", "totalMemory": "15.40 GB", "freeMemory": "2.50 GB" }, "node": { "version": "v24.11.1", "env": "development" }, "packageManager": { "name": "npm", "version": "11.7.0" }, "frameworks": [ { "name": "next", "version": "16.1.6" }, { "name": "react", "version": "19.2.3" } ], "databases": [ { "name": "pg", "version": "^8.20.0" }, { "name": "@prisma/client", "version": "^7.5.0" } ], "betterAuth": { "version": "^1.5.4", "config": { "baseURL": "http://localhost:3000/", "emailAndPassword": { "enabled": true }, "advanced": { "database": { "generateId": "serial" } }, "plugins": [ { "name": "admin", "config": { "id": "admin", "hooks": { "after": [ {} ] }, "endpoints": {}, "$ERROR_CODES": { "FAILED_TO_CREATE_USER": { "code": "FAILED_TO_CREATE_USER", "message": "Failed to create user" }, "USER_ALREADY_EXISTS": { "code": "USER_ALREADY_EXISTS", "message": "User already exists." }, "USER_ALREADY_EXISTS_USE_ANOTHER_EMAIL": { "code": "USER_ALREADY_EXISTS_USE_ANOTHER_EMAIL", "message": "User already exists. Use another email." }, "YOU_CANNOT_BAN_YOURSELF": { "code": "YOU_CANNOT_BAN_YOURSELF", "message": "You cannot ban yourself" }, "YOU_ARE_NOT_ALLOWED_TO_CHANGE_USERS_ROLE": { "code": "YOU_ARE_NOT_ALLOWED_TO_CHANGE_USERS_ROLE", "message": "You are not allowed to change users role" }, "YOU_ARE_NOT_ALLOWED_TO_CREATE_USERS": { "code": "YOU_ARE_NOT_ALLOWED_TO_CREATE_USERS", "message": "You are not allowed to create users" }, "YOU_ARE_NOT_ALLOWED_TO_LIST_USERS": { "code": "YOU_ARE_NOT_ALLOWED_TO_LIST_USERS", "message": "You are not allowed to list users" }, "YOU_ARE_NOT_ALLOWED_TO_LIST_USERS_SESSIONS": { "code": "YOU_ARE_NOT_ALLOWED_TO_LIST_USERS_SESSIONS", "message": "You are not allowed to list users sessions" }, "YOU_ARE_NOT_ALLOWED_TO_BAN_USERS": { "code": "YOU_ARE_NOT_ALLOWED_TO_BAN_USERS", "message": "You are not allowed to ban users" }, "YOU_ARE_NOT_ALLOWED_TO_IMPERSONATE_USERS": { "code": "YOU_ARE_NOT_ALLOWED_TO_IMPERSONATE_USERS", "message": "You are not allowed to impersonate users" }, "YOU_ARE_NOT_ALLOWED_TO_REVOKE_USERS_SESSIONS": { "code": "YOU_ARE_NOT_ALLOWED_TO_REVOKE_USERS_SESSIONS", "message": "You are not allowed to revoke users sessions" }, "YOU_ARE_NOT_ALLOWED_TO_DELETE_USERS": { "code": "YOU_ARE_NOT_ALLOWED_TO_DELETE_USERS", "message": "You are not allowed to delete users" }, "YOU_ARE_NOT_ALLOWED_TO_SET_USERS_PASSWORD": { "code": "YOU_ARE_NOT_ALLOWED_TO_SET_USERS_PASSWORD", "message": "You are not allowed to set users password" }, "BANNED_USER": { "code": "BANNED_USER", "message": "You have been banned from this application" }, "YOU_ARE_NOT_ALLOWED_TO_GET_USER": { "code": "YOU_ARE_NOT_ALLOWED_TO_GET_USER", "message": "You are not allowed to get user" }, "NO_DATA_TO_UPDATE": { "code": "NO_DATA_TO_UPDATE", "message": "No data to update" }, "YOU_ARE_NOT_ALLOWED_TO_UPDATE_USERS": { "code": "YOU_ARE_NOT_ALLOWED_TO_UPDATE_USERS", "message": "You are not allowed to update users" }, "YOU_CANNOT_REMOVE_YOURSELF": { "code": "YOU_CANNOT_REMOVE_YOURSELF", "message": "You cannot remove yourself" }, "YOU_ARE_NOT_ALLOWED_TO_SET_NON_EXISTENT_VALUE": { "code": "YOU_ARE_NOT_ALLOWED_TO_SET_NON_EXISTENT_VALUE", "message": "You are not allowed to set a non-existent role value" }, "YOU_CANNOT_IMPERSONATE_ADMINS": { "code": "YOU_CANNOT_IMPERSONATE_ADMINS", "message": "You cannot impersonate admins" }, "INVALID_ROLE_TYPE": { "code": "INVALID_ROLE_TYPE", "message": "Invalid role type" } }, "schema": { "user": { "fields": { "role": { "type": "string", "required": false, "input": false }, "banned": { "type": "boolean", "defaultValue": false, "required": false, "input": false }, "banReason": { "type": "string", "required": false, "input": false }, "banExpires": { "type": "date", "required": false, "input": false } } }, "session": { "fields": { "impersonatedBy": { "type": "string", "required": false } } } } } } ], "user": { "modelName": "users", "fields": { "id": "user_id", "emailVerified": "email_verified", "createdAt": "created_at", "updatedAt": "updated_at" } }, "session": { "fields": { "id": "session_id", "userId": "user_id", "expiresAt": "expires_at", "ipAddress": "ip_address", "userAgent": "user_agent", "createdAt": "created_at", "updatedAt": "updated_at" } }, "account": { "fields": { "accountId": "account_id", "userId": "user_id", "providerId": "provider_id", "accessToken": "[REDACTED]", "refreshToken": "[REDACTED]", "accessTokenExpiresAt": "access_token_expires_at", "refreshTokenExpiresAt": "refresh_token_expires_at", "idToken": "[REDACTED]", "createdAt": "created_at", "updatedAt": "updated_at" } }, "verification": { "fields": { "expiresAt": "expires_at", "createdAt": "created_at", "updatedAt": "updated_at" } } } } } ``` ### Which area(s) are affected? (Select all that apply) Other, Client ### Auth config (if applicable) ```typescript import "dotenv/config"; import { PrismaPg } from "@prisma/adapter-pg"; import { PrismaClient } from "@/generated/prisma/client"; import { betterAuth } from "better-auth"; import { prismaAdapter } from "better-auth/adapters/prisma"; import { admin } from "better-auth/plugins"; const adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL, connectionTimeoutMillis: 10000, idleTimeoutMillis: 10000, maxLifetimeSeconds: 30, max: 100, }); const client = new PrismaClient({ adapter }); export const auth = betterAuth({ database: prismaAdapter(client, { provider: "postgresql", debugLogs: true }), baseURL: "http://localhost:3000/", emailAndPassword: { enabled: true }, advanced: { database: { generateId: "serial", }, }, plugins: [admin()], user: { modelName: "users", fields: { id: "user_id", emailVerified: "email_verified", createdAt: "created_at", updatedAt: "updated_at", }, }, session: { fields: { id: "session_id", userId: "user_id", expiresAt: "expires_at", ipAddress: "ip_address", userAgent: "user_agent", createdAt: "created_at", updatedAt: "updated_at", }, }, account: { fields: { accountId: "account_id", userId: "user_id", providerId: "provider_id", accessToken: "access_token", refreshToken: "refresh_token", accessTokenExpiresAt: "access_token_expires_at", refreshTokenExpiresAt: "refresh_token_expires_at", idToken: "id_token", createdAt: "created_at", updatedAt: "updated_at", }, }, verification: { fields: { expiresAt: "expires_at", createdAt: "created_at", updatedAt: "updated_at", }, }, }); ``` ### Additional context I have been stuck at this for the last 2 days. Kindly help me solve this issue at earliest
GiteaMirror added the databasebug labels 2026-04-17 19:58:02 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Mar 26, 2026):

This is a known limitation in Better Auth — renaming the id field via the fields configuration is not supported and is silently ignored.

What's happening: When you configure id: "user_id", Better Auth ignores this mapping. The database correctly returns user_id: 1, but the transformOutput function looks for a field named id instead of user_id, resulting in id: undefined. This cascades to account creation failing with userId: undefined.

This has been reported and discussed in prior issues. The maintainer acknowledged it would be "definitely really difficult" to implement. There are two unmerged PRs attempting to fix this (#5873, #6056), but neither has been merged.

Workarounds:

  1. Use the default id column name (recommended): Modify your Prisma schema to use id instead of user_id, session_id, etc.

  2. SQL Views (PostgreSQL): Create views that alias your columns:

    CREATE VIEW users_ba AS SELECT user_id AS id, ... FROM users;
    

    Then point Better Auth at the view.

  3. Custom adapter: Write a thin wrapper around the Prisma adapter that handles the field name translation.

Unfortunately, until one of the open PRs gets merged, renaming primary key fields isn't supported. You may want to subscribe to #5807 or #6056 for updates.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Chat with Dosu Open in Cursor Join Discord Share on X

<!-- gh-comment-id:4131267921 --> @dosubot[bot] commented on GitHub (Mar 26, 2026): <!-- Answer --> This is a **known limitation** in Better Auth — renaming the `id` field via the `fields` configuration is not supported and is silently ignored. **What's happening**: When you configure `id: "user_id"`, Better Auth ignores this mapping. The database correctly returns `user_id: 1`, but the `transformOutput` function looks for a field named `id` instead of `user_id`, resulting in `id: undefined`. This cascades to account creation failing with `userId: undefined`. This has been [reported](https://github.com/better-auth/better-auth/issues/5807) and [discussed](https://github.com/better-auth/better-auth/issues/2480) in prior issues. The maintainer acknowledged it would be "definitely really difficult" to implement. There are two unmerged PRs attempting to fix this ([#5873](https://github.com/better-auth/better-auth/pull/5873), [#6056](https://github.com/better-auth/better-auth/pull/6056)), but neither has been merged. **Workarounds**: 1. **Use the default `id` column name** (recommended): Modify your Prisma schema to use `id` instead of `user_id`, `session_id`, etc. 2. **SQL Views** (PostgreSQL): Create views that alias your columns: ```sql CREATE VIEW users_ba AS SELECT user_id AS id, ... FROM users; ``` Then point Better Auth at the view. 3. **Custom adapter**: Write a thin wrapper around the Prisma adapter that handles the field name translation. Unfortunately, until one of the open PRs gets merged, renaming primary key fields isn't supported. You may want to subscribe to [#5807](https://github.com/better-auth/better-auth/issues/5807) or [#6056](https://github.com/better-auth/better-auth/pull/6056) for updates. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=brand-link).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/d436b4e9-52a2-4ee1-a6e7-ca67f5bc8e5a?feedback_type=great_response&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/d436b4e9-52a2-4ee1-a6e7-ca67f5bc8e5a?feedback_type=irrelevant_answer&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/d436b4e9-52a2-4ee1-a6e7-ca67f5bc8e5a?feedback_type=incorrect_sources&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/d436b4e9-52a2-4ee1-a6e7-ca67f5bc8e5a?feedback_type=too_verbose&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/d436b4e9-52a2-4ee1-a6e7-ca67f5bc8e5a?feedback_type=hallucination&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/d436b4e9-52a2-4ee1-a6e7-ca67f5bc8e5a?feedback_type=bug_report&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-bug_report) | [Other](https://app.dosu.dev/response-feedback/d436b4e9-52a2-4ee1-a6e7-ca67f5bc8e5a?feedback_type=other&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-other)</sup> [![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=chat-badge)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=This%20is%20a%20%2A%2Aknown%20limitation%2A%2A%20in%20Better%20Auth%20%E2%80%94%20renaming%20the%20%60id%60%20field%20via%20the%20%60fields%60%20configuration%20is%20not%20supported%20and%20is%20silently%20ignored.%0A%0A%2A%2AWhat%27s%20happening%2A%2A%3A%20When%20you%20configure%20%60id%3A%20%22user_id%22%60%2C%20Better%20Auth%20ignores%20this%20mapping.%20The%20database%20correctly%20returns%20%60user_id%3A%201%60%2C%20but%20the%20%60transformOutput%60%20function%20looks%20for%20a%20field%20named%20%60id%60%20instead%20of%20%60user_id%60%2C%20resulting%20in%20%60id%3A%20undefined%60.%20This%20cascades%20to%20account%20creation%20failing%20with%20%60userId%3A%20undefined%60.%0A%0AThis%20has%20been%20%5Breported%5D%28https%3A//github.com/better-auth/better-auth/issues/5807%29%20and%20%5Bdiscussed%5D%28https%3A//github.com/better-auth/better-auth/issues/2480%29%20in%20prior%20issues.%20The%20maintainer%20acknowledged%20it%20would%20be%20%22definitely%20really%20difficult%22%20to%20implement.%20There%20are%20two%20unmerged%20PRs%20attempting%20to%20fix%20this%20%28%5B%235873%5D%28https%3A//github.com/better-auth/better-auth/pull/5873%29%2C%20%5B%236056%5D%28https%3A//github.com/better-auth/better-auth/pull/6056%29%29%2C%20but%20neither%20has%20been%20merged.%0A%0A%2A%2AWorkarounds%2A%2A%3A%0A%0A1.%20%2A%2AUse%20the%20default%20%60id%60%20column%20name%2A%2A%20%28recommended%29%3A%20Modify%20your%20Prisma%20schema%20to%20use%20%60id%60%20instead%20of%20%60user_id%60%2C%20%60session_id%60%2C%20etc.%0A%0A2.%20%2A%2ASQL%20Views%2A%2A%20%28PostgreSQL%29%3A%20Create%20views%20that%20alias%20your%20columns%3A%0A%20%20%20%60%60%60sql%0A%20%20%20CREATE%20VIEW%20users_ba%20AS%20SELECT%20user_id%20AS%20id%2C%20...%20FROM%20users%3B%0A%20%20%20%60%60%60%0A%20%20%20Then%20point%20Better%20Auth%20at%20the%20view.%0A%0A3.%20%2A%2ACustom%20adapter%2A%2A%3A%20Write%20a%20thin%20wrapper%20around%20the%20Prisma%20adapter%20that%20handles%20the%20field%20name%20translation.%0A%0AUnfortunately%2C%20until%20one%20of%20the%20open%20PRs%20gets%20merged%2C%20renaming%20primary%20key%20fields%20isn%27t%20supported.%20You%20may%20want%20to%20subscribe%20to%20%5B%235807%5D%28https%3A//github.com/better-auth/better-auth/issues/5807%29%20or%20%5B%236056%5D%28https%3A//github.com/better-auth/better-auth/pull/6056%29%20for%20updates.)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=join-discord)&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/8779)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#28512