revert "fix(username): isUsernameAvailable should validate usernames (#3680)" (#3730)

This reverts commit e60f780f28.
This commit is contained in:
Bereket Engida
2025-07-31 23:53:32 -07:00
committed by GitHub
parent e60f780f28
commit 4d85d8709d
2 changed files with 0 additions and 29 deletions

View File

@@ -1,5 +0,0 @@
---
"better-auth": patch
---
fix(username): `isUsernameAvailable` should run validation

View File

@@ -268,30 +268,6 @@ export const username = (options?: UsernameOptions) => {
message: ERROR_CODES.INVALID_USERNAME,
});
}
const minUsernameLength = options?.minUsernameLength || 3;
const maxUsernameLength = options?.maxUsernameLength || 30;
if (username.length < minUsernameLength) {
throw new APIError("UNPROCESSABLE_ENTITY", {
message: ERROR_CODES.USERNAME_TOO_SHORT,
});
}
if (username.length > maxUsernameLength) {
throw new APIError("UNPROCESSABLE_ENTITY", {
message: ERROR_CODES.USERNAME_TOO_LONG,
});
}
const validator =
options?.usernameValidator || defaultUsernameValidator;
const valid = await validator(username);
if (!valid) {
throw new APIError("UNPROCESSABLE_ENTITY", {
message: ERROR_CODES.INVALID_USERNAME,
});
}
const user = await ctx.context.adapter.findOne<User>({
model: "user",
where: [