User Registration API Endpoint Failing #980

Closed
opened 2026-03-13 08:14:51 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @yeferson59 on GitHub (Apr 5, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

{
  statusCode: 400,
  message: 'Something went wrong',
  name: 'validation_error'
}
[object Object]

// next.js  --> server action
const requestHeaders = new Headers(await headers());
  
  const response = await fetch(`${baseUrl}/api/v1/auth/sign-up`, {
    method: "POST",
    headers: {
      ...requestHeaders,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      name: data.name,
      lastName: data.lastName,
      email: data.email,
      password: data.password,
      image: imageUrl,
    }),
  });

  if (!response.ok) {
    const result = await response.text();
    console.log(result)
    return {
      message: "Error al registrar el usuario",
      success: false,
    };
  }

  revalidatePath("/login");
  redirect("/login")


// express 
export const signUp = async (req: Request, res: Response) => {
  const { success, error, data } = await SignUpDto.safeParseAsync(req.body);

  if (!success) {
    res.status(400).json(error.flatten().fieldErrors);
    return;
  }

  await auth.api.signUpEmail({
    headers: fromNodeHeaders(req.headers),
    body: {
      name: data.name,
      lastName: data.lastName,
      email: data.email,
      password: data.password,
    },
  });
  if (data.image) {
    await db.query('UPDATE "user" SET "image" = $1 WHERE "email" = $2;', [
      data.image,
      data.email,
    ]);
  }
  res.sendStatus(201);
  return;
};

Current vs. Expected behavior

The validation step using SignUpDto.safeParseAsync() appears to succeed
The error occurs during the auth.api.signUpEmail() call
Because of this failure, the code never reaches the image update step
No user data is saved to the database

What version of Better Auth are you using?

1.2.5

Provide environment information

- OS MacOs Squoia 14.5
- Safari Version 18.4 (20621.1.15.11.10)

Which area(s) are affected? (Select all that apply)

Backend

Auth config (if applicable)

import { betterAuth } from "better-auth"
export const auth = betterAuth({
  emailAndPassword: {  
    enabled: true
  },
});

Additional context

No response

Originally created by @yeferson59 on GitHub (Apr 5, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce ```json { statusCode: 400, message: 'Something went wrong', name: 'validation_error' } [object Object] ``` ```typescript // next.js --> server action const requestHeaders = new Headers(await headers()); const response = await fetch(`${baseUrl}/api/v1/auth/sign-up`, { method: "POST", headers: { ...requestHeaders, "Content-Type": "application/json", }, body: JSON.stringify({ name: data.name, lastName: data.lastName, email: data.email, password: data.password, image: imageUrl, }), }); if (!response.ok) { const result = await response.text(); console.log(result) return { message: "Error al registrar el usuario", success: false, }; } revalidatePath("/login"); redirect("/login") // express export const signUp = async (req: Request, res: Response) => { const { success, error, data } = await SignUpDto.safeParseAsync(req.body); if (!success) { res.status(400).json(error.flatten().fieldErrors); return; } await auth.api.signUpEmail({ headers: fromNodeHeaders(req.headers), body: { name: data.name, lastName: data.lastName, email: data.email, password: data.password, }, }); if (data.image) { await db.query('UPDATE "user" SET "image" = $1 WHERE "email" = $2;', [ data.image, data.email, ]); } res.sendStatus(201); return; }; ``` ### Current vs. Expected behavior The validation step using SignUpDto.safeParseAsync() appears to succeed The error occurs during the auth.api.signUpEmail() call Because of this failure, the code never reaches the image update step No user data is saved to the database ### What version of Better Auth are you using? 1.2.5 ### Provide environment information ```bash - OS MacOs Squoia 14.5 - Safari Version 18.4 (20621.1.15.11.10) ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ emailAndPassword: { enabled: true }, }); ``` ### Additional context _No response_
GiteaMirror added the bug label 2026-03-13 08:14:51 -05:00
Author
Owner

@Kinfe123 commented on GitHub (Apr 5, 2025):

The issue mentioned is still showing the validation error that on safeParseAsync or pls share the latest error you are facing ?

@Kinfe123 commented on GitHub (Apr 5, 2025): The issue mentioned is still showing the validation error that on `safeParseAsync` or pls share the latest error you are facing ?
Author
Owner

@yeferson59 commented on GitHub (Apr 5, 2025):

This is latest error:
{
statusCode: 400,
message: 'Something went wrong',
name: 'validation_error'
}
[object Object]

It's of server side

@yeferson59 commented on GitHub (Apr 5, 2025): This is latest error: { statusCode: 400, message: 'Something went wrong', name: 'validation_error' } [object Object] It's of server side
Author
Owner

@Kinfe123 commented on GitHub (Apr 5, 2025):

this error is still showing me validation error please can you cross check your signupDto with req.body. try to log the body and see if it validates the Dto

@Kinfe123 commented on GitHub (Apr 5, 2025): this error is still showing me validation error please can you cross check your `signupDto` with `req.body`. try to log the body and see if it validates the Dto
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#980