{"record":{"id":"7bb1738c69ef1275","repo":"calcom/cal.diy","slug":"invalid-username","errorCode":null,"errorMessage":"Invalid username","messagePattern":"Invalid username","errorType":"http","errorClass":"HttpError","httpStatus":422,"severity":"warning","filePath":"apps/web/app/api/auth/signup/handlers/calcomSignupHandler.ts","lineNumber":88,"sourceCode":"  const shouldLockByDefault = await checkIfEmailIsBlockedInWatchlistController({\n    email: _email,\n    organizationId: null,\n    span: sentrySpan,\n  });\n\n  log.debug(\"handler\", { email: _email });\n\n  let username: string | null = usernameStatus.requestedUserName;\n  let checkoutSessionId: string | null = null;\n\n  // Check for premium username\n  if (usernameStatus.statusCode === 418) {\n    return NextResponse.json(usernameStatus.json, { status: 418 });\n  }\n\n  // Validate the user\n  if (!username) {\n    throw new HttpError({\n      statusCode: 422,\n      message: \"Invalid username\",\n    });\n  }\n\n  const email = _email.toLowerCase();\n\n  let foundToken: { id: number; teamId: number | null; expires: Date } | null = null;\n  if (token) {\n    foundToken = await findTokenByToken({ token });\n    throwIfTokenExpired(foundToken?.expires);\n    username = await validateAndGetCorrectedUsernameForTeam({\n      username,\n      email,\n      teamId: foundToken?.teamId ?? null,\n      isSignup: true,\n    });\n","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/calcom/cal.diy/blob/176037d0afbe572f870a3c702985e7cd83fe6c0c/apps/web/app/api/auth/signup/handlers/calcomSignupHandler.ts#L70-L106","documentation":"Thrown by calcomSignupHandler (HttpError, HTTP 422) when username is falsy after the premium-username check (statusCode !== 418 path). It means usernameStatus.requestedUserName resolved to null/empty, so there is no usable username to create the account with.","triggerScenarios":"Signup POST where the requested username is null or empty string and the premium-username service did not return a 418 (premium) response; a client that omits the username field entirely.","commonSituations":"Front-end sending username as undefined/null, an upstream username-suggestion service returning no candidate, a malformed signup form submission.","solutions":["Require a non-empty username client-side before enabling the submit button.","If using username auto-suggestion, ensure it always returns a candidate string before calling signup.","On 422 with 'Invalid username', regenerate a suggestion and retry rather than re-submitting the same empty value."],"exampleFix":"// before\nawait signup({ username: form.username }); // form.username may be null\n\n// after\nconst username = form.username?.trim();\nif (!username) {\n  setError('A username is required');\n  return;\n}\nawait signup({ username });","handlingStrategy":"validation","validationCode":"// Require a non-empty username before submitting signup\nconst username = (form.username ?? '').trim();\nif (username.length < 1) {\n  setError('username', 'A username is required');\n  return;\n}\nawait signup({ username, email: form.email });","typeGuard":"function isNonEmptyUsername(v: unknown): v is string {\n  return typeof v === 'string' && v.trim().length >= 1;\n}","tryCatchPattern":"try {\n  await signup(payload);\n} catch (e) {\n  if (e instanceof HttpError && e.statusCode === 422 && /Invalid username/.test(e.message)) {\n    suggestNewUsername(); // regenerate a candidate\n    return;\n  }\n  throw e;\n}","preventionTips":["Disable submit until a non-empty username is present.","If using username auto-suggestion, guarantee it returns a non-empty string."],"tags":["signup","auth","username","validation"],"backgroundTag":null,"analyzedSha":"176037d0afbe572f870a3c702985e7cd83fe6c0c","analyzedAt":"2026-08-12T19:12:41.464Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}