{"record":{"id":"933c989876592938","repo":"calcom/cal.diy","slug":"username-or-email-is-already-taken","errorCode":null,"errorMessage":"Username or email is already taken","messagePattern":"Username or email is already taken","errorType":"http","errorClass":"HttpError","httpStatus":409,"severity":"warning","filePath":"apps/web/app/api/auth/signup/handlers/calcomSignupHandler.ts","lineNumber":121,"sourceCode":"      teamId: foundToken?.teamId ?? null,\n      isSignup: true,\n    });\n\n    if (foundToken?.teamId) {\n      const existingUser = await userRepository.findByEmailWithInvitedTo({email})\n\n      if (existingUser && existingUser.invitedTo !== foundToken.teamId) {\n        return NextResponse.json({ message: SIGNUP_ERROR_CODES.USER_ALREADY_EXISTS }, { status: 409 });\n      }\n    }\n  } else {\n    const usernameAndEmailValidation = await validateAndGetCorrectedUsernameAndEmail({\n      username,\n      email,\n      isSignup: true,\n    });\n    if (!usernameAndEmailValidation.isValid) {\n      throw new HttpError({\n        statusCode: 409,\n        message: \"Username or email is already taken\",\n      });\n    }\n\n    if (!usernameAndEmailValidation.username) {\n      throw new HttpError({\n        statusCode: 422,\n        message: \"Invalid username\",\n      });\n    }\n\n    username = usernameAndEmailValidation.username;\n  }\n\n  // Create the customer in Stripe with ad tracking metadata\n  const cookieStore = await cookies();\n  const cookiesObj = Object.fromEntries(cookieStore.getAll().map((c) => [c.name, c.value]));","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/calcom/cal.diy/blob/176037d0afbe572f870a3c702985e7cd83fe6c0c/apps/web/app/api/auth/signup/handlers/calcomSignupHandler.ts#L103-L139","documentation":"Thrown by calcomSignupHandler (HttpError, HTTP 409) when validateAndGetCorrectedUsernameAndEmail reports isValid === false in the non-team-invite signup branch. HTTP 409 signals a conflict: the username or email is already owned by an existing account.","triggerScenarios":"Signup POST with a username or email that already exists in the database, when no valid team-invite token is present (the token branch handles team members separately and returns a 409 JSON instead).","commonSituations":"User re-registering with the same email, choosing a taken username, leftover account from a failed prior signup, case/whitespace differences not normalized before the check.","solutions":["Pre-check username/email availability (debounced) before submit and suggest alternatives.","Normalize email to lowercase and trim before checking, matching the handler's userEmail.toLowerCase().","On 409, prompt login/password-reset instead of re-registration.","If the user was invited to a team, include the invite token so the team branch resolves ownership rather than conflicting."],"exampleFix":"// before\nawait signup({ username, email });\n\n// after\nconst avail = await checkUsernameEmail({ username, email });\nif (!avail.isValid) {\n  setErrors({ username: 'taken', email: 'taken' });\n  return;\n}\nawait signup({ username: avail.username ?? username, email: email.toLowerCase() });","handlingStrategy":"validation","validationCode":"// Debounced availability check before signup\nconst ok = await checkAvailability({ username, email: email.toLowerCase() });\nif (!ok.available) {\n  setErrors({ username: ok.usernameTaken ? 'Username taken' : undefined,\n              email: ok.emailTaken ? 'Email taken' : undefined });\n  return;\n}\nawait signup({ username, email: email.toLowerCase() });","typeGuard":"function isAvailabilityResult(v: unknown): v is { isValid: boolean; username?: string } {\n  return !!v && typeof v === 'object' &&\n    typeof (v as any).isValid === 'boolean';\n}","tryCatchPattern":"try {\n  await signup(payload);\n} catch (e) {\n  if (e instanceof HttpError && e.statusCode === 409) {\n    promptLoginOrReset(); // offer login/reset instead of re-register\n    return;\n  }\n  throw e;\n}","preventionTips":["Normalize email to lower-case before both availability check and signup.","Suggest alternative usernames when the chosen one is taken.","If invited to a team, always include the invite token."],"tags":["signup","auth","conflict","duplicate","username","email"],"backgroundTag":null,"analyzedSha":"176037d0afbe572f870a3c702985e7cd83fe6c0c","analyzedAt":"2026-08-12T19:12:41.464Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}