mirror of
https://github.com/simstudioai/sim.git
synced 2026-09-24 15:45:35 +08:00
fix(auth): show "account already exists" on duplicate email signup (#4855)
* fix(auth): show "account already exists" on duplicate email signup * fix(auth): use exact path match for duplicate-email signup check
This commit is contained in:
@@ -844,6 +844,22 @@ export const auth = betterAuth({
|
||||
}
|
||||
}
|
||||
|
||||
if (ctx.path === '/sign-up/email' && ctx.body?.email) {
|
||||
const signupEmail = ctx.body.email.toLowerCase()
|
||||
const [existingUser] = await db
|
||||
.select({ id: schema.user.id })
|
||||
.from(schema.user)
|
||||
.where(eq(schema.user.email, signupEmail))
|
||||
.limit(1)
|
||||
|
||||
if (existingUser) {
|
||||
throw new APIError('UNPROCESSABLE_ENTITY', {
|
||||
message: 'User already exists',
|
||||
code: 'USER_ALREADY_EXISTS',
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}),
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user