{"record":{"id":"5e2b744b7bb384e8","repo":"mastra-ai/mastra","slug":"errordata-message-failed-to-create-account","errorCode":null,"errorMessage":"${errorData.message || 'Failed to create account'}","messagePattern":"\\$\\{errorData\\.message \\|\\| 'Failed to create account'\\}","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"auth/better-auth/src/index.ts","lineNumber":812,"sourceCode":"  async signUp(\n    email: string,\n    password: string,\n    name: string | undefined,\n    request: Request,\n  ): Promise<CredentialsResult<EEUser>> {\n    const displayName = name ?? email.split('@')[0] ?? 'User';\n    const headers = request?.headers ?? new Headers();\n\n    // Use asResponse: true to get the full response with Set-Cookie headers\n    const response = await this.auth.api.signUpEmail({\n      body: { email, password, name: displayName },\n      headers,\n      asResponse: true,\n    });\n\n    if (!response.ok) {\n      const errorData = (await response.json().catch(() => ({}))) as { message?: string };\n      throw new Error(errorData.message || 'Failed to create account');\n    }\n\n    const result = (await response.json()) as { user?: User; token?: string | null };\n\n    if (!result?.user) {\n      throw new Error('Failed to create account');\n    }\n\n    // Extract Set-Cookie headers from Better Auth response\n    const cookies: string[] = [];\n    const setCookieHeader = response.headers.get('set-cookie');\n    if (setCookieHeader) {\n      // Split multiple cookies (they may be comma-separated or in multiple headers)\n      cookies.push(...setCookieHeader.split(/,(?=\\s*\\w+=)/));\n    }\n\n    return {\n      user: mapBetterAuthUserToEEUser(result.user),","sourceCodeStart":794,"sourceCodeEnd":830,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/auth/better-auth/src/index.ts#L794-L830","documentation":"signUp() calls Better Auth's sign-up endpoint (auth.api.signUpEmail with asResponse: true). On a non-OK response it parses the JSON body for a `message` and throws it, defaulting to 'Failed to create account'. The message usually carries Better Auth's reason: user already exists, weak password, validation failure.","triggerScenarios":"signUp({ email, password, name }) where auth.api.signUpEmail returns response.ok === false — duplicate email (USER_ALREADY_EXISTS), password below min length policy, invalid email format, or database write failure; errorData.message replaces the default when present.","commonSituations":"Re-registering an existing account during tests without cleanup; passwords that violate better-auth's password config (minPasswordLength); sign-up attempted before the users table/migration exists in the auth database.","solutions":["Read errorData.message to identify the concrete cause — for duplicates, sign in instead or use a unique email.","Ensure the password meets the configured policy (better-auth default minPasswordLength: 8).","Verify the auth database is migrated (users/account tables exist) and writable.","For tests, reset or truncate auth tables between runs to avoid duplicate-email conflicts."],"exampleFix":"// before: password shorter than better-auth default (8 chars)\nawait auth.signUp({ email: 'new@example.com', password: 'short', name: 'X' });\n\n// after\nawait auth.signUp({ email: 'new@example.com', password: 'hunter2secure', name: 'X' });","handlingStrategy":"try-catch","validationCode":"function isValidSignUpInput(input: { email: string; password: string; name: string }): boolean {\n  return /^[^@\\s]+@[^@\\s]+\\.[^@\\s]+$/.test(input.email)\n    && input.password.length >= 8\n    && input.name.trim().length > 0;\n}","typeGuard":"function isSignUpRejection(e: unknown): e is Error {\n  return e instanceof Error && (e.message === 'Failed to create account' || /already exists|password/i.test(e.message));\n}","tryCatchPattern":"try {\n  await provider.signUp({ email, password, name });\n} catch (e) {\n  if (isSignUpRejection(e)) {\n    if (/already exists/i.test(e.message)) return { ok: false, reason: 'email-taken' };\n    if (/password/i.test(e.message)) return { ok: false, reason: 'weak-password' };\n    return { ok: false, reason: 'signup-failed', detail: e.message };\n  }\n  throw e;\n}","preventionTips":["Validate email format and password policy client-side before calling signUp.","Truncate auth tables between CI test runs to avoid duplicate-email conflicts.","Run better-auth migrations so users/accounts tables exist before sign-up."],"tags":["authentication","signup","better-auth","http-4xx"],"backgroundTag":"signup-rejected","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}