inferAdditionalFields<typeof auth>() #1083

Closed
opened 2026-03-13 08:21:46 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @RAGAdox on GitHub (Apr 19, 2025).

Originally assigned to: @ping-maxwell on GitHub.

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

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

This is not a good practice , referencing auth in client side code requires all the dependencies present in server side auth object and might expose security implementations.

Current vs. Expected behavior

This is not a good practice , referencing auth in client side code requires all the dependencies present in server side auth object and might expose security implementations.

What version of Better Auth are you using?

1.2.7

Provide environment information

OS independent

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

Package

Auth config (if applicable)

import { betterAuth } from "better-auth"
export const auth = betterAuth({
  emailAndPassword: {  
    enabled: true
  },
emailVerification: {
    expiresIn: 3600,
    autoSignInAfterVerification: true,
    sendVerificationEmail: async ({ user, url }, request) => {
      await sendEmail({
        to: user.email,
        subject: "Verification Request",
        text: `Click the link to verify your email: ${url}`,
      });
    },
  },
});

Additional context

No response

Originally created by @RAGAdox on GitHub (Apr 19, 2025). Originally assigned to: @ping-maxwell on GitHub. ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce ``` export const authClient = createAuthClient({ plugins: [inferAdditionalFields<typeof auth>()], }); ``` This is not a good practice , referencing `auth` in client side code requires all the dependencies present in server side `auth` object and might expose security implementations. ### Current vs. Expected behavior This is not a good practice , referencing `auth` in client side code requires all the dependencies present in server side `auth` object and might expose security implementations. ### What version of Better Auth are you using? 1.2.7 ### Provide environment information ```bash OS independent ``` ### Which area(s) are affected? (Select all that apply) Package ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ emailAndPassword: { enabled: true }, emailVerification: { expiresIn: 3600, autoSignInAfterVerification: true, sendVerificationEmail: async ({ user, url }, request) => { await sendEmail({ to: user.email, subject: "Verification Request", text: `Click the link to verify your email: ${url}`, }); }, }, }); ``` ### Additional context _No response_
GiteaMirror added the enhancementwontfix labels 2026-03-13 08:21:46 -05:00
Author
Owner

@ping-maxwell commented on GitHub (Apr 20, 2025):

If you import auth using type only, this will be would fine.

eg:

import type { auth } from "./auth.ts";

There are two alternative solutions to getting type-safety provided by the inferAdditionalFields plugin.
First option is to make createAuthClient similar to TRPc, to have types inferred from server side to client side. But that's out of the question as everything can be agnostic, and would mean the server auth could be bundled into the client which we don't want.
The other option is to manually type out each type but that's a really bad experience.

@ping-maxwell commented on GitHub (Apr 20, 2025): If you import `auth` using `type` only, this will be would fine. eg: ```ts import type { auth } from "./auth.ts"; ``` There are two alternative solutions to getting type-safety provided by the `inferAdditionalFields` plugin. First option is to make `createAuthClient` similar to TRPc, to have types inferred from server side to client side. But that's out of the question as everything can be agnostic, and would mean the server auth could be bundled into the client which we don't want. The other option is to manually type out each type but that's a really bad experience.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1083