SignUp/In Email Error Handling #201

Closed
opened 2026-03-13 07:37:22 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @abegehr on GitHub (Nov 10, 2024).

Describe the bug
When calling signUp.email() or signIn.email(), it doesn't return an error object but returns the error message in response.data.
Examples:

  1. [Debug] signUp.email -> {data: {message: "Password is too short"}, error: null} (LoginEmail.svelte, line 54)
  2. [Debug] signIn.email -> {data: {message: "Invalid email or password"}, error: null} (LoginEmail.svelte, line 62)

To Reproduce

Use this super simple signUp/signIn test:

      // try sign-up
      const res1 = await auth.signUp.email({
        email: "test@test.com,
        password: "123",
        name: "test",
      });
      console.debug("DEBUG signUp.email ->", res1);

      // try sign-in
      const res2 = await auth.signIn.email({
        email: "a@a"
        password: "1234567890"
      });
      console.debug("DEBUG signIn.email ->", res2);

Expected behavior
I would expect the error messages to show under res.error.

Desktop (please complete the following information):

  • OS: macOS 15.1
  • Browser Safari
  • Version 18.1

Additional context
My backend is running on Astro: https://www.better-auth.com/docs/integrations/astro

Originally created by @abegehr on GitHub (Nov 10, 2024). **Describe the bug** When calling `signUp.email()` or `signIn.email()`, it doesn't return an error object but returns the error message in response.data. Examples: 1. [Debug] signUp.email -> {data: {message: "Password is too short"}, error: null} (LoginEmail.svelte, line 54) 2. [Debug] signIn.email -> {data: {message: "Invalid email or password"}, error: null} (LoginEmail.svelte, line 62) **To Reproduce** Use this super simple signUp/signIn test: ```ts // try sign-up const res1 = await auth.signUp.email({ email: "test@test.com, password: "123", name: "test", }); console.debug("DEBUG signUp.email ->", res1); // try sign-in const res2 = await auth.signIn.email({ email: "a@a" password: "1234567890" }); console.debug("DEBUG signIn.email ->", res2); ``` **Expected behavior** I would expect the error messages to show under `res.error`. **Desktop (please complete the following information):** - OS: macOS 15.1 - Browser Safari - Version 18.1 **Additional context** My backend is running on Astro: https://www.better-auth.com/docs/integrations/astro
Author
Owner

@abegehr commented on GitHub (Nov 10, 2024):

Having a look at browser network, it turns out the request to Astro BE returns with status 200, which seems to be the problem. I'd assume this is an issue with the Astro adapter/handler, since it does show the error with onAPIError.onError:

14:15:37 [200] POST /api/auth/sign-up/email 2ms
DEBUG [APIError [BetterCallAPIError]: API Error: BAD_REQUEST Invalid email] {
  status: 'BAD_REQUEST',
  headers: Headers { 'Content-Type': 'application/json' },
  body: { message: 'Invalid email' },
  [cause]: { message: 'Invalid email' }
}
@abegehr commented on GitHub (Nov 10, 2024): Having a look at browser network, it turns out the request to Astro BE returns with status 200, which seems to be the problem. I'd assume this is an issue with the Astro adapter/handler, since it does show the error with `onAPIError.onError`: ``` 14:15:37 [200] POST /api/auth/sign-up/email 2ms DEBUG [APIError [BetterCallAPIError]: API Error: BAD_REQUEST Invalid email] { status: 'BAD_REQUEST', headers: Headers { 'Content-Type': 'application/json' }, body: { message: 'Invalid email' }, [cause]: { message: 'Invalid email' } } ```
Author
Owner

@abegehr commented on GitHub (Nov 10, 2024):

After some investigation, I figured out that the issue was in my CORS middleware, which didn't respect response status. Closing 👍

@abegehr commented on GitHub (Nov 10, 2024): After some investigation, I figured out that the issue was in my CORS middleware, which didn't respect response status. Closing 👍
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#201