API signUpEmail not throwing error

Hello there, I'm new here. I love working with better-auth, is been really great so far!

Here is my problem:

After upgrading from v1.1.20 to latest, running:
  const response = await auth.api.signUpEmail({
      asResponse: true,
      body: { name, email, password },
    });

, no longer throws an error, if, for example, the email is taken. Can anyone tell me why this was changed, and how to upgrade to latest? Thank you!

Here is the full code, I have a react-router app:

  try {
    // If the email is taken, this will throw an APIError error
    const response = await auth.api.signUpEmail({
      // I need this so that I can set the headers below
      asResponse: true,
      body: { name, email, password },
    });

    return redirect(redirectTo, {
      // Setting the `Set-Cookie` header here, this will authenticate the user
      headers: response.headers,
    });
  } catch (error) {
    if (error instanceof APIError) {
      // Here we have the APIError, with our error message
      // See: https://www.better-auth.com/docs/concepts/api#error-handling
      return data(
        {
          // This is for form management, ignore
          result: submission.reply({
            hideFields: ["password"],
            formErrors: [error.body.message ?? error.message],
          }),
        },
        { status: 400 },
      );
    }

    throw error;
  }
Was this page helpful?