calcom/cal.diy · warning · HttpError

Invalid username

Error message

Invalid username

What it means

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.

Source

Thrown at apps/web/app/api/auth/signup/handlers/calcomSignupHandler.ts:88

  const shouldLockByDefault = await checkIfEmailIsBlockedInWatchlistController({
    email: _email,
    organizationId: null,
    span: sentrySpan,
  });

  log.debug("handler", { email: _email });

  let username: string | null = usernameStatus.requestedUserName;
  let checkoutSessionId: string | null = null;

  // Check for premium username
  if (usernameStatus.statusCode === 418) {
    return NextResponse.json(usernameStatus.json, { status: 418 });
  }

  // Validate the user
  if (!username) {
    throw new HttpError({
      statusCode: 422,
      message: "Invalid username",
    });
  }

  const email = _email.toLowerCase();

  let foundToken: { id: number; teamId: number | null; expires: Date } | null = null;
  if (token) {
    foundToken = await findTokenByToken({ token });
    throwIfTokenExpired(foundToken?.expires);
    username = await validateAndGetCorrectedUsernameForTeam({
      username,
      email,
      teamId: foundToken?.teamId ?? null,
      isSignup: true,
    });

View on GitHub (pinned to 176037d0af)

Solutions

  1. Require a non-empty username client-side before enabling the submit button.
  2. If using username auto-suggestion, ensure it always returns a candidate string before calling signup.
  3. On 422 with 'Invalid username', regenerate a suggestion and retry rather than re-submitting the same empty value.

Example fix

// before
await signup({ username: form.username }); // form.username may be null

// after
const username = form.username?.trim();
if (!username) {
  setError('A username is required');
  return;
}
await signup({ username });
Defensive patterns

Strategy: validation

Validate before calling

// Require a non-empty username before submitting signup
const username = (form.username ?? '').trim();
if (username.length < 1) {
  setError('username', 'A username is required');
  return;
}
await signup({ username, email: form.email });

Type guard

function isNonEmptyUsername(v: unknown): v is string {
  return typeof v === 'string' && v.trim().length >= 1;
}

Try / catch

try {
  await signup(payload);
} catch (e) {
  if (e instanceof HttpError && e.statusCode === 422 && /Invalid username/.test(e.message)) {
    suggestNewUsername(); // regenerate a candidate
    return;
  }
  throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: Front-end sending username as undefined/null, an upstream username-suggestion service returning no candidate, a malformed signup form submission.

Related errors


AI-assisted analysis of calcom/cal.diy@176037d0af (2026-08-12). Data as JSON: /api/errors/7bb1738c69ef1275. Report an issue: GitHub.