[GH-ISSUE #4870] user.additionalFields aren't being returned when using admin.listUsers or session.user #27418

Closed
opened 2026-04-17 18:26:02 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @jd-solanki on GitHub (Sep 24, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/4870

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Hi 👋🏻

I'm showing users table in admin and using admin.listUsers to get the data. However, I'm not getting the columns I already mentioned in user.additionalFields config.

Here's how I configured:

export const auth = betterAuth({
  additionalFields: {
    lastSignInAt: {
      type: 'date',
      fieldName: 'last_sign_in_at',
      validator: {
        input: z.iso.datetime(),
      },
      required: true,
      input: false,
    },
    deactivatedAt: {
      type: 'date',
      fieldName: 'deactivated_at',
      validator: {
        input: z.nullable(z.iso.datetime()),
      },
      required: false,
      input: false,
    },
  },
})

However, user inference is also configured, and it shows those additional fields in types, but can't get in the actual JS object.

export type Session = typeof auth.$Infer.Session
export type User = Simplify<Omit<Session['user'], 'id'> & { id: number }>
// Shows `lastSignInAt` & `deactivatedAt` under `User` type

Apart from admin.listUsers, I'm also not getting them when a user signs in (session.user).

Here's steps:

  1. Setup betterAuth
  2. Add additionalFields in user options
  3. Add admin plugin
  4. use authClient.admin.listUsers to retreive the records
  5. Notice additionalFields added in config isn't returned

Current vs. Expected behavior

Right now using authClient.admin.listUsers or user sesssion session.user doesn't return any additional fields.

I expect BetterAuth to return those fields in both user session, listUsers and other places if any where we fetch user details.

What version of Better Auth are you using?

1.3.14

System info

{
  "system": {
    "platform": "darwin",
    "arch": "arm64",
    "version": "Darwin Kernel Version 24.6.0: Mon Jul 14 11:30:40 PDT 2025; root:xnu-11417.140.69~1/RELEASE_ARM64_T6041",
    "release": "24.6.0",
    "cpuCount": 12,
    "cpuModel": "Apple M4 Pro",
    "totalMemory": "48.00 GB",
    "freeMemory": "0.14 GB"
  },
  "node": {
    "version": "v22.19.0",
    "env": "development"
  },
  "packageManager": {
    "name": "npm",
    "version": "10.9.3"
  },
  "frameworks": [
    {
      "name": "vue",
      "version": "^3.5.21"
    },
    {
      "name": "nuxt",
      "version": "^4.1.2"
    }
  ],
  "databases": [
    {
      "name": "pg",
      "version": "^8.16.3"
    },
    {
      "name": "drizzle",
      "version": "^0.44.5"
    }
  ],
  "betterAuth": {
    "version": "^1.3.14",
    "config": null
  }
}

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

Package, Client, Backend

Auth config (if applicable)

import { polar } from '@polar-sh/better-auth'
import { betterAuth } from 'better-auth'
import { admin, magicLink } from 'better-auth/plugins'
import * as z from 'zod'

export const auth = betterAuth({
  user: {
    // Docs: https://www.better-auth.com/docs/concepts/database#extending-core-schema
    additionalFields: {
      lastSignInAt: {
        type: 'date',
        fieldName: 'last_sign_in_at',
        validator: {
          input: z.iso.datetime(),
        },
        required: true,
        input: false,
      },
      deactivatedAt: {
        type: 'date',
        fieldName: 'deactivated_at',
        validator: {
          input: z.nullable(z.iso.datetime()),
        },
        required: false,
        input: false,
      },
    },
  },
  plugins: [
    admin(),
    polar({ /* ... */ }),
    magicLink({ /* ... */ }),
  ],
})

Additional context

Discord Thread link where another user is also facing the same.

Originally created by @jd-solanki on GitHub (Sep 24, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/4870 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce Hi 👋🏻 I'm showing users table in admin and using `admin.listUsers` to get the data. However, I'm not getting the columns I already mentioned in `user.additionalFields` config. Here's how I configured: ```ts export const auth = betterAuth({ additionalFields: { lastSignInAt: { type: 'date', fieldName: 'last_sign_in_at', validator: { input: z.iso.datetime(), }, required: true, input: false, }, deactivatedAt: { type: 'date', fieldName: 'deactivated_at', validator: { input: z.nullable(z.iso.datetime()), }, required: false, input: false, }, }, }) ``` However, user inference is also configured, and it shows those additional fields in types, but can't get in the actual JS object. ```ts export type Session = typeof auth.$Infer.Session export type User = Simplify<Omit<Session['user'], 'id'> & { id: number }> // Shows `lastSignInAt` & `deactivatedAt` under `User` type ``` Apart from `admin.listUsers`, I'm also not getting them when a user signs in (`session.user`). Here's steps: 1. Setup betterAuth 2. Add `additionalFields` in `user` options 3. Add admin plugin 4. use `authClient.admin.listUsers` to retreive the records 5. Notice additionalFields added in config isn't returned ### Current vs. Expected behavior Right now using `authClient.admin.listUsers` or user sesssion `session.user` doesn't return any additional fields. I expect BetterAuth to return those fields in both user session, `listUsers` and other places if any where we fetch user details. ### What version of Better Auth are you using? 1.3.14 ### System info ```bash { "system": { "platform": "darwin", "arch": "arm64", "version": "Darwin Kernel Version 24.6.0: Mon Jul 14 11:30:40 PDT 2025; root:xnu-11417.140.69~1/RELEASE_ARM64_T6041", "release": "24.6.0", "cpuCount": 12, "cpuModel": "Apple M4 Pro", "totalMemory": "48.00 GB", "freeMemory": "0.14 GB" }, "node": { "version": "v22.19.0", "env": "development" }, "packageManager": { "name": "npm", "version": "10.9.3" }, "frameworks": [ { "name": "vue", "version": "^3.5.21" }, { "name": "nuxt", "version": "^4.1.2" } ], "databases": [ { "name": "pg", "version": "^8.16.3" }, { "name": "drizzle", "version": "^0.44.5" } ], "betterAuth": { "version": "^1.3.14", "config": null } } ``` ### Which area(s) are affected? (Select all that apply) Package, Client, Backend ### Auth config (if applicable) ```typescript import { polar } from '@polar-sh/better-auth' import { betterAuth } from 'better-auth' import { admin, magicLink } from 'better-auth/plugins' import * as z from 'zod' export const auth = betterAuth({ user: { // Docs: https://www.better-auth.com/docs/concepts/database#extending-core-schema additionalFields: { lastSignInAt: { type: 'date', fieldName: 'last_sign_in_at', validator: { input: z.iso.datetime(), }, required: true, input: false, }, deactivatedAt: { type: 'date', fieldName: 'deactivated_at', validator: { input: z.nullable(z.iso.datetime()), }, required: false, input: false, }, }, }, plugins: [ admin(), polar({ /* ... */ }), magicLink({ /* ... */ }), ], }) ``` ### Additional context Discord Thread [link](https://discord.com/channels/1288403910284935179/1419958301873016903) where another user is also facing the [same](https://discord.com/channels/1288403910284935179/1419958301873016903/1420056102124654602).
GiteaMirror added the lockedbug labels 2026-04-17 18:26:03 -05:00
Author
Owner

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

The reason your additionalFields (like lastSignInAt and deactivatedAt) aren't showing up in admin.listUsers or session.user is that Better Auth only includes fields in runtime user/session objects if they're actually present in your database and returned by your adapter. TypeScript will infer the fields, but unless they're stored and loaded from the DB, they won't appear in the JS object at runtime. The returned property in your config only affects types and validation, not what gets sent to the client or included in API responses reference.

To fix this, make sure those fields exist in your user table and are included in your adapter's queries. If you want more control over what gets returned in the session, you can use the customSession plugin to manually include extra fields, but this may require additional DB queries.

If you already have the fields in your DB and they're still missing, double-check your migrations and adapter config, and ensure there are no version mismatches or caching issues reference.

Let me know if you need help debugging your adapter or DB schema!

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:3327256915 --> @dosubot[bot] commented on GitHub (Sep 24, 2025): <!-- Answer --> The reason your `additionalFields` (like `lastSignInAt` and `deactivatedAt`) aren't showing up in `admin.listUsers` or `session.user` is that Better Auth only includes fields in runtime user/session objects if they're actually present in your database and returned by your adapter. TypeScript will infer the fields, but unless they're stored and loaded from the DB, they won't appear in the JS object at runtime. The `returned` property in your config only affects types and validation, not what gets sent to the client or included in API responses [reference](https://github.com/better-auth/better-auth/issues/3888#issuecomment-3168778445). To fix this, make sure those fields exist in your user table and are included in your adapter's queries. If you want more control over what gets returned in the session, you can use the [customSession plugin](https://www.better-auth.com/docs/concepts/session-management#customizing-session-response) to manually include extra fields, but this may require additional DB queries. If you already have the fields in your DB and they're still missing, double-check your migrations and adapter config, and ensure there are no version mismatches or caching issues [reference](https://github.com/better-auth/better-auth/issues/512). Let me know if you need help debugging your adapter or DB schema! <!-- 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/8da9f682-be71-401b-9eb5-c63e8157c2d9?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/8da9f682-be71-401b-9eb5-c63e8157c2d9?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/8da9f682-be71-401b-9eb5-c63e8157c2d9?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/8da9f682-be71-401b-9eb5-c63e8157c2d9?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/8da9f682-be71-401b-9eb5-c63e8157c2d9?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/8da9f682-be71-401b-9eb5-c63e8157c2d9?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/8da9f682-be71-401b-9eb5-c63e8157c2d9?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/4870)
Author
Owner

@jd-solanki commented on GitHub (Sep 24, 2025):

Hi @dosu

I have drizzle adapter, and my database has those fields already migrated to the DB. I can manually update them from my app as well which confirms that DB has those fields and works as expected. It's just BetterAuth that isn't returning those fields.

As per the docs here: https://www.better-auth.com/docs/concepts/database#extending-core-schema

Adding fields in user.additionalFields config, we should get them in session.user.

<!-- gh-comment-id:3327304623 --> @jd-solanki commented on GitHub (Sep 24, 2025): Hi @dosu I have drizzle adapter, and my database has those fields already migrated to the DB. I can manually update them from my app as well which confirms that DB has those fields and works as expected. It's just BetterAuth that isn't returning those fields. As per the docs here: https://www.better-auth.com/docs/concepts/database#extending-core-schema Adding fields in `user.additionalFields` config, we should get them in `session.user`.
Author
Owner

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

This is a known issue with the drizzle adapter: if you set the fieldName property in additionalFields, it must match the ORM schema field name exactly. Otherwise, the field will be undefined in the session or user object, even if it exists in the database reference. The recommended fix is to either remove fieldName from your config or ensure it matches the actual field name in your Drizzle schema.

Also, double-check your drizzleAdapter config to make sure you're mapping Better Auth keys to your DB columns correctly. For example, if your DB column is last_sign_in_at, your adapter config should map it like:

user: { ...schema.users, lastSignInAt: 'last_sign_in_at' }

If you want more control over what gets returned in the session, you can use the customSession plugin to manually include extra fields.

If you update your config and the fields are still missing, please share your drizzleAdapter config and user table schema so I can help debug further.

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:3327318252 --> @dosubot[bot] commented on GitHub (Sep 24, 2025): <!-- Answer --> This is a known issue with the drizzle adapter: if you set the `fieldName` property in `additionalFields`, it must match the ORM schema field name exactly. Otherwise, the field will be undefined in the session or user object, even if it exists in the database [reference](https://github.com/better-auth/better-auth/issues/1968). The recommended fix is to either remove `fieldName` from your config or ensure it matches the actual field name in your Drizzle schema. Also, double-check your drizzleAdapter config to make sure you're mapping Better Auth keys to your DB columns correctly. For example, if your DB column is `last_sign_in_at`, your adapter config should map it like: ```ts user: { ...schema.users, lastSignInAt: 'last_sign_in_at' } ``` If you want more control over what gets returned in the session, you can use the [customSession plugin](https://www.better-auth.com/docs/concepts/session-management#customizing-session-response) to manually include extra fields. If you update your config and the fields are still missing, please share your drizzleAdapter config and user table schema so I can help debug further. <!-- 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/0c6a4fa0-4941-4729-8a52-0c00312f474b?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/0c6a4fa0-4941-4729-8a52-0c00312f474b?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/0c6a4fa0-4941-4729-8a52-0c00312f474b?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/0c6a4fa0-4941-4729-8a52-0c00312f474b?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/0c6a4fa0-4941-4729-8a52-0c00312f474b?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/0c6a4fa0-4941-4729-8a52-0c00312f474b?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/0c6a4fa0-4941-4729-8a52-0c00312f474b?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/4870)
Author
Owner

@jd-solanki commented on GitHub (Sep 24, 2025):

@dosu Removing fieldName resolved the issue. It would be great to mention this in the docs.

Thanks, closing this.

P.S. @Bekacru I can add PR for the docs but I might not be aware of all the caveats so it'll be great if you can add this in docs.

<!-- gh-comment-id:3327346452 --> @jd-solanki commented on GitHub (Sep 24, 2025): @dosu Removing `fieldName` resolved the issue. It would be great to mention this in the docs. Thanks, closing this. > _P.S. @Bekacru I can add PR for the docs but I might not be aware of all the caveats so it'll be great if you can add this in docs._
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#27418