{"record":{"id":"209e2a67245aeb7e","repo":"mastra-ai/mastra","slug":"failed-to-create-account","errorCode":null,"errorMessage":"Failed to create account","messagePattern":"Failed to create account","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"auth/better-auth/src/index.ts","lineNumber":818,"sourceCode":"    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),\n      token: result.token ?? undefined,\n      cookies,\n    };\n  }\n\n  /**","sourceCodeStart":800,"sourceCodeEnd":836,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/auth/better-auth/src/index.ts#L800-L836","documentation":"If signUp() receives an OK (2xx) response but the parsed JSON body lacks result.user, the provider throws 'Failed to create account'. It is a defensive check for a success response that doesn't confirm a created user, indicating the server response shape doesn't match expectations.","triggerScenarios":"signUp({ email, password, name }) where response.ok === true but `result?.user` is falsy — empty body, better-auth version returning a different success payload, or middleware/proxy stripping the JSON body.","commonSituations":"better-auth version mismatch changing signUpEmail's return shape; a 200 returned after email-verification-required flows that don't include the user object; proxies or test harnesses returning empty 200s.","solutions":["Align the installed better-auth version with the one this provider targets (check peer dependency range).","Log the raw signUp response body to inspect the actual payload shape.","Check whether email verification is enabled and handle the verification-required flow instead of expecting a user object."],"exampleFix":"// before: email verification enabled -> 2xx with no user in body\nawait auth.signUp({ email, password, name });\n\n// after: disable verification for local/test, or handle the verify flow\nconst ba = betterAuth({ emailAndPassword: { requireEmailVerification: false }, ... });","handlingStrategy":"type-guard","validationCode":"if (res.ok) {\n  const body = await res.json();\n  if (!body?.user) console.warn('signUp returned 2xx without user; possible email-verification flow or version mismatch');\n}","typeGuard":"function isSignUpResult(r: unknown): r is { user: User; token?: string | null } {\n  return typeof r === 'object' && r !== null && 'user' in r && (r as { user: unknown }).user != null;\n}","tryCatchPattern":"try {\n  const result = await provider.signUp({ email, password, name });\n  if (!isSignUpResult(result)) throw new Error('Sign-up succeeded but no user was returned');\n} catch (e) {\n  if (e instanceof Error && e.message === 'Failed to create account') {\n    console.error('Check better-auth version and email-verification settings');\n  }\n  throw e;\n}","preventionTips":["Align requireEmailVerification settings with the code path that expects a user in the response.","Add a contract test asserting signUp() returns a user in your CI environment.","Pin better-auth versions and review changelogs before upgrading."],"tags":["authentication","signup","response-shape","better-auth"],"backgroundTag":"unexpected-response-shape","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}