From 1cb5a1653b65d2f5bcd15da0df6d68b5029c8ca0 Mon Sep 17 00:00:00 2001 From: Waleed Date: Tue, 2 Jun 2026 18:54:53 -0700 Subject: [PATCH] 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 --- apps/sim/lib/auth/auth.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/apps/sim/lib/auth/auth.ts b/apps/sim/lib/auth/auth.ts index 40037c938c..76465b45be 100644 --- a/apps/sim/lib/auth/auth.ts +++ b/apps/sim/lib/auth/auth.ts @@ -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 }), },