mirror of
https://github.com/better-auth/better-auth.git
synced 2026-07-31 20:05:38 -05:00
feat(username): export the correct error codes for the plugin
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user