authClient.$ERROR_CODES to include codes from included plugins #537

Closed
opened 2026-03-13 07:51:42 -05:00 by GiteaMirror · 5 comments
Owner

Originally created by @arfath-linklet on GitHub (Jan 8, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

For instance: when emailOTPClient in included

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

Current vs. Expected behavior

expecting authClient.$ERROR_CODES to include all of:

$ERROR_CODES: {
    readonly OTP_EXPIRED: "otp expired";
    readonly INVALID_OTP: "invalid otp";
    readonly INVALID_EMAIL: "invalid email";
    readonly USER_NOT_FOUND: "user not found";
};

What version of Better Auth are you using?

1.1.10

Provide environment information

-

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

Client

Auth config (if applicable)

import { betterAuth } from "better-auth"
export const auth = betterAuth({
  plugins: [
    emailOTP({
      expiresIn: ...,
      disableSignUp: false,
    }),
    magicLink({
      expiresIn: ...,
      disableSignUp: false
    }),
  ],
});

Additional context

No response

Originally created by @arfath-linklet on GitHub (Jan 8, 2025). ### Is this suited for github? - [X] Yes, this is suited for github ### To Reproduce For instance: when emailOTPClient in included ``` const authClient = createAuthClient({ baseURL, plugins: [emailOTPClient(), inferAdditionalFields<typeof auth>()], }); ``` ### Current vs. Expected behavior expecting `authClient.$ERROR_CODES` to include all of: ``` $ERROR_CODES: { readonly OTP_EXPIRED: "otp expired"; readonly INVALID_OTP: "invalid otp"; readonly INVALID_EMAIL: "invalid email"; readonly USER_NOT_FOUND: "user not found"; }; ``` ### What version of Better Auth are you using? 1.1.10 ### Provide environment information ```bash - ``` ### Which area(s) are affected? (Select all that apply) Client ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ plugins: [ emailOTP({ expiresIn: ..., disableSignUp: false, }), magicLink({ expiresIn: ..., disableSignUp: false }), ], }); ``` ### Additional context _No response_
GiteaMirror added the bug label 2026-03-13 07:51:42 -05:00
Author
Owner

@vniehues commented on GitHub (Mar 4, 2025):

@arfath-linklet did you find a solution to this? I'm currently facing the same issue

@vniehues commented on GitHub (Mar 4, 2025): @arfath-linklet did you find a solution to this? I'm currently facing the same issue
Author
Owner

@vniehues commented on GitHub (Mar 4, 2025):

Small update:
I found a workaround but it's not pretty.

basically you move your plugin config out of the main config into a const and then can get the types like this:

const adminPluginConfig = admin();
plugins: [
    adminPluginConfig,
    orgPluginConfig
]
type AuthClientErrorCodes = typeof authClient.$ERROR_CODES;

type OrganizationErrorCodes = {
    [K in keyof typeof orgPluginConfig.$ERROR_CODES]: string;
};

type AdminErrorCodes = {
    [K in keyof typeof adminPluginConfig.$ERROR_CODES]: string;
};

export type AuthErrorCodes = AuthClientErrorCodes & OrganizationErrorCodes & AdminErrorCodes & {
    INVALID_INVITATION: string;
};
@vniehues commented on GitHub (Mar 4, 2025): Small update: I found a workaround but it's not pretty. basically you move your plugin config out of the main config into a const and then can get the types like this: ``` const adminPluginConfig = admin(); ``` ``` plugins: [ adminPluginConfig, orgPluginConfig ] ``` ``` type AuthClientErrorCodes = typeof authClient.$ERROR_CODES; type OrganizationErrorCodes = { [K in keyof typeof orgPluginConfig.$ERROR_CODES]: string; }; type AdminErrorCodes = { [K in keyof typeof adminPluginConfig.$ERROR_CODES]: string; }; export type AuthErrorCodes = AuthClientErrorCodes & OrganizationErrorCodes & AdminErrorCodes & { INVALID_INVITATION: string; }; ```
Author
Owner

@aymericfontaine commented on GitHub (Apr 3, 2025):

$ERROR_CODES does not include TWO_FACTOR_ERROR_CODES from the twoFactor() plugin, defined in
8d35723221/packages/better-auth/src/plugins/two-factor/error-code.ts (L1)

Could $ERROR_CODES be extended to incorporate error codes from integrated plugins like twoFactor()? This enhancement would promote consistency and simplify error management for applications utilizing these plugins.

@aymericfontaine commented on GitHub (Apr 3, 2025): `$ERROR_CODES` does not include `TWO_FACTOR_ERROR_CODES` from the `twoFactor()` plugin, defined in https://github.com/better-auth/better-auth/blob/8d35723221e5ac6b030a5ca65579375b79675b90/packages/better-auth/src/plugins/two-factor/error-code.ts#L1 Could `$ERROR_CODES` be extended to incorporate error codes from integrated plugins like `twoFactor()`? This enhancement would promote consistency and simplify error management for applications utilizing these plugins.
Author
Owner

@elvince commented on GitHub (Jun 2, 2025):

Hi,

Can we expect that the error_codes are 'merged' by the client so we have all error_codes that we are using? or at least all error_codes?

It's pretty bad that we had to do tweak like https://github.com/better-auth/better-auth/issues/1155#issuecomment-2699041689

Thanks and keep making this library great!

@elvince commented on GitHub (Jun 2, 2025): Hi, Can we expect that the error_codes are 'merged' by the client so we have all error_codes that we are using? or at least all error_codes? It's pretty bad that we had to do tweak like https://github.com/better-auth/better-auth/issues/1155#issuecomment-2699041689 Thanks and keep making this library great!
Author
Owner

@ping-maxwell commented on GitHub (Aug 11, 2025):

All client plugins do not infer the error codes from the server-side plugins, this means the only way to get the ERROR_CODES per plugin is from your auth config's auth.$ERROR_CODES

@ping-maxwell commented on GitHub (Aug 11, 2025): All client plugins do not infer the error codes from the server-side plugins, this means the only way to get the ERROR_CODES per plugin is from your auth config's `auth.$ERROR_CODES`
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#537