From e09ceae2d6ec5959a2ca81562368a8fa014abdd9 Mon Sep 17 00:00:00 2001 From: Bereket Engida Date: Sun, 13 Apr 2025 00:10:07 +0300 Subject: [PATCH] feat(username): export the correct error codes for the plugin --- .../better-auth/src/plugins/username/error-codes.ts | 9 +++++++++ packages/better-auth/src/plugins/username/index.ts | 13 ++----------- 2 files changed, 11 insertions(+), 11 deletions(-) create mode 100644 packages/better-auth/src/plugins/username/error-codes.ts diff --git a/packages/better-auth/src/plugins/username/error-codes.ts b/packages/better-auth/src/plugins/username/error-codes.ts new file mode 100644 index 0000000000..659b7be056 --- /dev/null +++ b/packages/better-auth/src/plugins/username/error-codes.ts @@ -0,0 +1,9 @@ +export const USERNAME_ERROR_CODES = { + INVALID_USERNAME_OR_PASSWORD: "invalid username or password", + EMAIL_NOT_VERIFIED: "email not verified", + UNEXPECTED_ERROR: "unexpected error", + USERNAME_IS_ALREADY_TAKEN: "username is already taken. please try another.", + USERNAME_TOO_SHORT: "username is too short", + USERNAME_TOO_LONG: "username is too long", + INVALID_USERNAME: "username is invalid", +}; diff --git a/packages/better-auth/src/plugins/username/index.ts b/packages/better-auth/src/plugins/username/index.ts index 875e417b95..d4f5df7a52 100644 --- a/packages/better-auth/src/plugins/username/index.ts +++ b/packages/better-auth/src/plugins/username/index.ts @@ -6,9 +6,9 @@ import type { Account, InferOptionSchema, User } from "../../types"; import { setSessionCookie } from "../../cookies"; import { sendVerificationEmailFn } from "../../api"; import { BASE_ERROR_CODES } from "../../error/codes"; -import { TWO_FACTOR_ERROR_CODES } from "../two-factor/error-code"; import { schema } from "./schema"; import { mergeSchema } from "../../db/schema"; +import { USERNAME_ERROR_CODES as ERROR_CODES } from "./error-codes"; export type UsernameOptions = { schema?: InferOptionSchema; @@ -37,15 +37,6 @@ function defaultUsernameValidator(username: string) { } export const username = (options?: UsernameOptions) => { - const ERROR_CODES = { - INVALID_USERNAME_OR_PASSWORD: "invalid username or password", - EMAIL_NOT_VERIFIED: "email not verified", - UNEXPECTED_ERROR: "unexpected error", - USERNAME_IS_ALREADY_TAKEN: "username is already taken. please try another.", - USERNAME_TOO_SHORT: "username is too short", - USERNAME_TOO_LONG: "username is too long", - INVALID_USERNAME: "username is invalid", - }; return { id: "username", endpoints: { @@ -300,6 +291,6 @@ export const username = (options?: UsernameOptions) => { }, ], }, - $ERROR_CODES: TWO_FACTOR_ERROR_CODES, + $ERROR_CODES: ERROR_CODES, } satisfies BetterAuthPlugin; };