feat(username): export the correct error codes for the plugin

This commit is contained in:
Bereket Engida
2025-04-13 00:10:07 +03:00
parent 6be9c58de9
commit e09ceae2d6
2 changed files with 11 additions and 11 deletions
@@ -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",
};
@@ -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<typeof schema>;
@@ -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;
};