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 }), },