[GH-ISSUE #7982] inferAdditionalFields is not working #10961

Closed
opened 2026-04-13 07:21:09 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @hieudien14310 on GitHub (Feb 15, 2026).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/7982

Originally assigned to: @bytaesu on GitHub.

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Please refer to the attached screenshot for the reproduction steps

Current vs. Expected behavior

Current: Type inference is not working.

Expecte: Types should be correctly inferred.

What version of Better Auth are you using?

^1.4.18

System info

MacOs

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

Client

Auth config (if applicable)

import { betterAuth } from "better-auth";
import { admin } from "better-auth/plugins/admin";
import { openAPI } from "better-auth/plugins";
import { Pool } from "pg";
export const auth = betterAuth({
  trustedOrigins: [process.env.FE_URL!],
  database: new Pool({
    connectionString: process.env.PG_DB_URL!,
  }),
  emailAndPassword: {
    enabled: true,
  },
  user: {
    additionalFields: {
      phone: { type: "string", required: false },
    },
  },
  session: {
    expiresIn: 3 * 24 * 60 * 60,
    updateAge: 24 * 60 * 60,
  },
  plugins: [openAPI(), admin()],
});

Additional context

Image

I’m following the second method (https://www.better-auth.com/docs/concepts/typescript#inferring-additional-fields-on-client) from the documentation to infer additional fields.
However, the phone field is not being inferred correctly, and TypeScript is throwing an error
I using Vite + React + Typescript

Originally created by @hieudien14310 on GitHub (Feb 15, 2026). Original GitHub issue: https://github.com/better-auth/better-auth/issues/7982 Originally assigned to: @bytaesu on GitHub. ### Is this suited for github? - [ ] Yes, this is suited for github ### To Reproduce Please refer to the attached screenshot for the reproduction steps ### Current vs. Expected behavior Current: Type inference is not working. Expecte: Types should be correctly inferred. ### What version of Better Auth are you using? ^1.4.18 ### System info ```bash MacOs ``` ### Which area(s) are affected? (Select all that apply) Client ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth"; import { admin } from "better-auth/plugins/admin"; import { openAPI } from "better-auth/plugins"; import { Pool } from "pg"; export const auth = betterAuth({ trustedOrigins: [process.env.FE_URL!], database: new Pool({ connectionString: process.env.PG_DB_URL!, }), emailAndPassword: { enabled: true, }, user: { additionalFields: { phone: { type: "string", required: false }, }, }, session: { expiresIn: 3 * 24 * 60 * 60, updateAge: 24 * 60 * 60, }, plugins: [openAPI(), admin()], }); ``` ### Additional context <img width="1440" height="580" alt="Image" src="https://github.com/user-attachments/assets/a61829b5-34ee-4af1-94a0-11501d9d9f75" /> I’m following the second method (https://www.better-auth.com/docs/concepts/typescript#inferring-additional-fields-on-client) from the documentation to infer additional fields. However, the phone field is not being inferred correctly, and TypeScript is throwing an error I using Vite + React + Typescript
GiteaMirror added the enhancementlocked labels 2026-04-13 07:21:09 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Feb 15, 2026):

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

The inferAdditionalFields plugin requires explicit type imports from your server auth configuration - it can't infer types automatically at runtime.

For your setup (server and client in the same project), make sure you're passing the server auth type as a generic parameter:

// auth-client.ts
import { createAuthClient } from "better-auth/react";
import { inferAdditionalFields } from "better-auth/client/plugins";
import type { auth } from "./path-to-your-server-auth"; // Import the type

export const authClient = createAuthClient({
  plugins: [inferAdditionalFields<typeof auth>()],
  baseURL: "...",
});

If you're already doing this and it's still not working, check your tsconfig.json for these known problematic settings:

  • Set "exactOptionalPropertyTypes": false (this flag breaks plugin field inference)
  • Use "moduleResolution": "nodenext" or "bundler" instead of "node"

Also, if you have dynamic functions in your auth config (like async trustedOrigins), they can prevent TypeScript from narrowing the config to a concrete type. Try extracting your config as a const:

const config = {
  user: {
    additionalFields: {
      phone: { type: "string", required: false },
    },
  },
  // ...
} as const;

export const auth = betterAuth(config);

Could you share your auth-client.ts file to confirm how you're importing the type?

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:3904789408 --> @dosubot[bot] commented on GitHub (Feb 15, 2026): <!-- Greeting --> Hi @hieudien14310! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> The `inferAdditionalFields` plugin requires **explicit type imports from your server auth configuration** - it can't infer types automatically at runtime. For your setup (server and client in the same project), make sure you're passing the server auth type as a generic parameter: ```typescript // auth-client.ts import { createAuthClient } from "better-auth/react"; import { inferAdditionalFields } from "better-auth/client/plugins"; import type { auth } from "./path-to-your-server-auth"; // Import the type export const authClient = createAuthClient({ plugins: [inferAdditionalFields<typeof auth>()], baseURL: "...", }); ``` If you're already doing this and it's still not working, check your `tsconfig.json` for these [known problematic settings](https://github.com/better-auth/better-auth/issues/5940): - Set `"exactOptionalPropertyTypes": false` (this flag breaks plugin field inference) - Use `"moduleResolution": "nodenext"` or `"bundler"` instead of `"node"` Also, if you have dynamic functions in your auth config (like async `trustedOrigins`), they can [prevent TypeScript from narrowing the config to a concrete type](https://github.com/better-auth/better-auth/issues/7261). Try extracting your config as a const: ```typescript const config = { user: { additionalFields: { phone: { type: "string", required: false }, }, }, // ... } as const; export const auth = betterAuth(config); ``` Could you share your `auth-client.ts` file to confirm how you're importing the type? <!-- 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/2abf6156-c02b-461f-8cad-644fc6585e04?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/2abf6156-c02b-461f-8cad-644fc6585e04?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/2abf6156-c02b-461f-8cad-644fc6585e04?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/2abf6156-c02b-461f-8cad-644fc6585e04?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/2abf6156-c02b-461f-8cad-644fc6585e04?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/2abf6156-c02b-461f-8cad-644fc6585e04?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/2abf6156-c02b-461f-8cad-644fc6585e04?feedback_type=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)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=The%20%60inferAdditionalFields%60%20plugin%20requires%20%2A%2Aexplicit%20type%20imports%20from%20your%20server%20auth%20configuration%2A%2A%20-%20it%20can%27t%20infer%20types%20automatically%20at%20runtime.%0A%0AFor%20your%20setup%20%28server%20and%20client%20in%20the%20same%20project%29%2C%20make%20sure%20you%27re%20passing%20the%20server%20auth%20type%20as%20a%20generic%20parameter%3A%0A%0A%60%60%60typescript%0A//%20auth-client.ts%0Aimport%20%7B%20createAuthClient%20%7D%20from%20%22better-auth/react%22%3B%0Aimport%20%7B%20inferAdditionalFields%20%7D%20from%20%22better-auth/client/plugins%22%3B%0Aimport%20type%20%7B%20auth%20%7D%20from%20%22./path-to-your-server-auth%22%3B%20//%20Import%20the%20type%0A%0Aexport%20const%20authClient%20%3D%20createAuthClient%28%7B%0A%20%20plugins%3A%20%5BinferAdditionalFields%3Ctypeof%20auth%3E%28%29%5D%2C%0A%20%20baseURL%3A%20%22...%22%2C%0A%7D%29%3B%0A%60%60%60%0A%0AIf%20you%27re%20already%20doing%20this%20and%20it%27s%20still%20not%20working%2C%20check%20your%20%60tsconfig.json%60%20for%20these%20%5Bknown%20problematic%20settings%5D%28https%3A//github.com/better-auth/better-auth/issues/5940%29%3A%0A-%20Set%20%60%22exactOptionalPropertyTypes%22%3A%20false%60%20%28this%20flag%20breaks%20plugin%20field%20inference%29%0A-%20Use%20%60%22moduleResolution%22%3A%20%22nodenext%22%60%20or%20%60%22bundler%22%60%20instead%20of%20%60%22node%22%60%0A%0AAlso%2C%20if%20you%20have%20dynamic%20functions%20in%20your%20auth%20config%20%28like%20async%20%60trustedOrigins%60%29%2C%20they%20can%20%5Bprevent%20TypeScript%20from%20narrowing%20the%20config%20to%20a%20concrete%20type%5D%28https%3A//github.com/better-auth/better-auth/issues/7261%29.%20Try%20extracting%20your%20config%20as%20a%20const%3A%0A%0A%60%60%60typescript%0Aconst%20config%20%3D%20%7B%0A%20%20user%3A%20%7B%0A%20%20%20%20additionalFields%3A%20%7B%0A%20%20%20%20%20%20phone%3A%20%7B%20type%3A%20%22string%22%2C%20required%3A%20false%20%7D%2C%0A%20%20%20%20%7D%2C%0A%20%20%7D%2C%0A%20%20//%20...%0A%7D%20as%20const%3B%0A%0Aexport%20const%20auth%20%3D%20betterAuth%28config%29%3B%0A%60%60%60%0A%0ACould%20you%20share%20your%20%60auth-client.ts%60%20file%20to%20confirm%20how%20you%27re%20importing%20the%20type%3F)&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/7982)
Author
Owner

@bytaesu commented on GitHub (Feb 15, 2026):

Hi @hieudien14310,

Thanks for letting us know. I'll check!

<!-- gh-comment-id:3905306851 --> @bytaesu commented on GitHub (Feb 15, 2026): Hi @hieudien14310, Thanks for letting us know. I'll check!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#10961