Significant-Gravitas/AutoGPT · error · Error

Failed to update email

Error message

Failed to update email

What it means

Fallback message from updateEmailViaAuthAPI in the settings AccountCard: PUT /api/auth/user with {email}; on failure it safely parses the body with .catch(() => ({})) and surfaces error.error, defaulting to 'Failed to update email' only when the body is unparseable or has no error field. This is the hardened twin of the profile EmailForm helper (error 29) — same endpoint, same semantics, safer JSON handling.

Source

Thrown at autogpt_platform/frontend/src/app/(platform)/settings/account/components/AccountCard/useAccountCard.ts:29

const emailSchema = z.object({
  email: z
    .string()
    .min(1, "Email is required")
    .email("Enter a valid email address"),
});

type EmailFormValues = z.infer<typeof emailSchema>;

async function updateEmailViaAuthAPI(email: string) {
  const response = await fetch("/api/auth/user", {
    method: "PUT",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({ email }),
  });

  if (!response.ok) {
    const error = await response.json().catch(() => ({}));
    throw new Error(error.error ?? "Failed to update email");
  }

  return response.json();
}

export function useAccountCard({ user }: { user: User }) {
  const currentEmail = user.email ?? "";

  const emailForm = useForm<EmailFormValues>({
    resolver: zodResolver(emailSchema),
    defaultValues: { email: currentEmail },
    mode: "onChange",
  });

  const [isUpdatingEmail, setIsUpdatingEmail] = useState(false);

  async function onSubmitEmail(values: EmailFormValues): Promise<boolean> {
    if (values.email === currentEmail) return false;

View on GitHub (pinned to 9c8bb5550f)

Solutions

  1. Inspect the PUT response body/status in DevTools; the generic message means no JSON error was returned.
  2. 401/redirect → sign in again; 400 → verify the email isn't already registered.
  3. If it's consistently generic, check the /api/auth/user route's server logs — it may be erroring before producing JSON.
  4. Deduplicate: this logic exists twice (here and profile EmailForm) — converge on this safer version.
Defensive patterns

Strategy: try-catch

Validate before calling

const parsed = emailSchema.safeParse(email);
if (!parsed.success) { /* block submit */ }

Type guard

function isEmailUpdateFailure(err: unknown): boolean {
  return err instanceof Error && err.message === "Failed to update email";
}

Try / catch

try {
  await updateEmailViaAuthAPI(email);
} catch (error) {
  if (isEmailUpdateFailure(error)) { /* session/config issue — check status in network tab */ }
  toast({ description: (error as Error).message, variant: "destructive" });
}

Prevention

When it happens

Trigger: PUT /api/auth/user returning non-ok with no usable JSON error: email already exists (but body missing error field), invalid email format, expired auth cookie yielding a redirect/HTML response, or the route itself crashing to an HTML 500.

Common situations: Duplicate email attempts; session expiry in long-lived settings tabs; Supabase configuration drift in self-hosted setups.

Related errors


AI-assisted analysis of Significant-Gravitas/AutoGPT@9c8bb5550f (2026-08-14). Data as JSON: /api/errors/c00cdcf002bb3e0e. Report an issue: GitHub.