mirror of
https://github.com/better-auth/better-auth.git
synced 2026-05-25 08:31:37 -05:00
fix: return proper error on conflict username
This commit is contained in:
@@ -69,7 +69,6 @@ export const signUpEmail = <O extends BetterAuthOptions>() =>
|
||||
message: "Password is too long",
|
||||
});
|
||||
}
|
||||
|
||||
const dbUser = await ctx.context.internalAdapter.findUserByEmail(email);
|
||||
if (dbUser?.user) {
|
||||
ctx.context.logger.info(`Sign-up attempt for existing email: ${email}`);
|
||||
@@ -82,15 +81,28 @@ export const signUpEmail = <O extends BetterAuthOptions>() =>
|
||||
ctx.context.options,
|
||||
additionalFields as any,
|
||||
);
|
||||
const createdUser = await ctx.context.internalAdapter.createUser({
|
||||
email: email.toLowerCase(),
|
||||
name,
|
||||
image,
|
||||
...additionalData,
|
||||
emailVerified: false,
|
||||
});
|
||||
let createdUser: User;
|
||||
try {
|
||||
createdUser = await ctx.context.internalAdapter.createUser({
|
||||
email: email.toLowerCase(),
|
||||
name,
|
||||
image,
|
||||
...additionalData,
|
||||
emailVerified: false,
|
||||
});
|
||||
if (!createdUser) {
|
||||
throw new APIError("BAD_REQUEST", {
|
||||
message: "Failed to create user",
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
throw new APIError("UNPROCESSABLE_ENTITY", {
|
||||
message: "Failed to create user",
|
||||
details: e,
|
||||
});
|
||||
}
|
||||
if (!createdUser) {
|
||||
throw new APIError("BAD_REQUEST", {
|
||||
throw new APIError("UNPROCESSABLE_ENTITY", {
|
||||
message: "Failed to create user",
|
||||
});
|
||||
}
|
||||
|
||||
@@ -42,7 +42,6 @@ export const updateUser = <O extends BetterAuthOptions>() =>
|
||||
});
|
||||
}
|
||||
const additionalFields = parseUserInput(ctx.context.options, rest);
|
||||
console.log({ additionalFields });
|
||||
const user = await ctx.context.internalAdapter.updateUserByEmail(
|
||||
session.user.email,
|
||||
{
|
||||
|
||||
@@ -25,7 +25,7 @@ describe("username", async (it) => {
|
||||
expect(res.data?.user.username).toBe("new-username");
|
||||
});
|
||||
const headers = new Headers();
|
||||
it("should signin with username", async () => {
|
||||
it("should sign-in with username", async () => {
|
||||
const res = await client.signIn.username(
|
||||
{
|
||||
username: "new-username",
|
||||
|
||||
Reference in New Issue
Block a user