{"record":{"id":"0234b854bacea503","repo":"langfuse/langfuse","slug":"user-with-email-already-exists-please-sign-in","errorCode":null,"errorMessage":"User with email already exists. Please sign in.","messagePattern":"User with email already exists\\. Please sign in\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"web/src/features/auth-credentials/lib/credentialsServerUtils.ts","lineNumber":35,"sourceCode":"  password: string,\n  name: string,\n  options?: {\n    /** Ad-platform click ids, see getAdClickIdsFromRequest */\n    adClickIds?: AdClickIds;\n  },\n) {\n  if (!isValidPassword(password))\n    throw new Error(\"Password needs to be at least 8 characters long.\");\n\n  const hashedPassword = await hashPassword(password);\n  // check that no user exists with this email\n  const user = await prisma.user.findUnique({\n    where: {\n      email: email.toLowerCase(),\n    },\n  });\n  if (user !== null) {\n    throw new Error(\n      user.password !== null\n        ? \"User with email already exists. Please sign in.\"\n        : \"You have already signed up via an identity provider. Please sign in.\",\n    );\n  }\n\n  const newUser = await prisma.user.create({\n    data: {\n      email: email.toLowerCase(),\n      password: hashedPassword,\n      name,\n    },\n  });\n\n  await createProjectMembershipsOnSignup(newUser, {\n    userWasJustCreated: true,\n    adClickIds: options?.adClickIds,\n  });","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/langfuse/langfuse/blob/59d92c7cf365150d10b753b5a0d1708902a2ed60/web/src/features/auth-credentials/lib/credentialsServerUtils.ts#L17-L53","documentation":"createUserEmailPassword checks for an existing user by lowercased email; if one exists it throws, with the message depending on whether the existing account has a password. Credentials-based accounts get 'User with email already exists. Please sign in.' while SSO-created accounts get the identity-provider message.","triggerScenarios":"Calling signup with an email that already registered with email/password (user.password !== null). Duplicate-tab signups, double form submissions, or retrying signup after a partial success.","commonSituations":"User already signed up previously and forgot; race where two signup requests with the same email land nearly simultaneously; testing signup with an already-used fixture email.","solutions":["Sign in with the existing account instead (or use password reset if forgotten).","On the client, catch this message and redirect to the sign-in flow.","Guard against duplicate submission by disabling the submit button while in flight."],"exampleFix":"// before\nawait createUserEmailPassword('existing@user.com', 'password123');\n\n// after\nconst user = await prisma.user.findUnique({ where: { email } });\nif (user) {\n  // route to sign-in / password reset instead of signup\n  return redirectToSignin();\n}\nawait createUserEmailPassword(email, 'password123');","handlingStrategy":"validation","validationCode":"const existing = await findUserByEmail(email);\nif (existing) { /* route to sign-in or reset */ }","typeGuard":null,"tryCatchPattern":"try { await createUserEmailPassword(email, pwd); }\ncatch (e) {\n  if (e instanceof Error && e.message.includes('already exists')) return signIn(email, pwd);\n  throw e;\n}","preventionTips":["Check for an existing account before offering signup.","Disable submit buttons during the request to prevent duplicate signups."],"tags":["auth","signup","duplicate-email"],"backgroundTag":"email-already-registered","analyzedSha":"59d92c7cf365150d10b753b5a0d1708902a2ed60","analyzedAt":"2026-08-27T22:22:00.402Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}