[GH-ISSUE #1394] No Response from API in Next.js Despite Correct Payload and Headers #26051

Closed
opened 2026-04-17 16:27:17 -05:00 by GiteaMirror · 5 comments
Owner

Originally created by @F-47 on GitHub (Feb 9, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/1394

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Develop a NestJS backend and integrate it with BetterAuth.
  2. Set up BetterAuth in Next.js according to the documentation and configure it with a custom baseUrl.
  3. Create sign-up and login forms.
  4. Clicking the sign-up or login button does not trigger a request; it simply returns without any action.

Current vs. Expected behavior

Issue with Signup Request
I'm currently working on a signup form and facing an issue where no response is received when submitting the form.

My Setup:
Signup Form:
Image

Auth Client (auth-client.ts):
Image

auth.ts
Image

API Route (route.ts):
Image

Signup Form Headers:
Image

The payload is sent correctly, and the headers are properly set:
Image

However, no response is received after submission:
Image

Testing the same URL and payload in Postman works fine.
Need Help:
What could be causing the request to work in Postman but not in my Next.js app? Any insights would be appreciated!

What version of Better Auth are you using?

1.1.16

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Pro
  Available memory (MB): 49078
  Available CPU cores: 12
Binaries:
  Node: 20.13.1
  npm: 10.5.2
  Yarn: 1.22.21
  pnpm: N/A
Relevant Packages:
  next: 15.1.6 // Latest available version is detected (15.1.6).
  eslint-config-next: 15.1.6
  react: 19.0.0
  react-dom: 19.0.0
  typescript: 5.7.3
Next.js Config:
  output: N/A

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

Client

Auth config (if applicable)

import { betterAuth } from "better-auth";

export const auth = betterAuth({
  emailAndPassword: {
    enabled: true,
  },
});

Additional context

No response

Originally created by @F-47 on GitHub (Feb 9, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/1394 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Develop a NestJS backend and integrate it with BetterAuth. 2. Set up BetterAuth in Next.js according to the documentation and configure it with a custom baseUrl. 3. Create sign-up and login forms. 4. Clicking the sign-up or login button does not trigger a request; it simply returns without any action. ### Current vs. Expected behavior Issue with Signup Request I'm currently working on a signup form and facing an issue where no response is received when submitting the form. My Setup: Signup Form: ![Image](https://github.com/user-attachments/assets/44de41a2-74b6-4197-9ab7-694f630c7035) Auth Client (auth-client.ts): ![Image](https://github.com/user-attachments/assets/404bc5c4-f24e-4473-b35e-12543890fcdb) auth.ts ![Image](https://github.com/user-attachments/assets/9ad8bf37-32d8-4170-89c3-c36e6a481757) API Route (route.ts): ![Image](https://github.com/user-attachments/assets/359c3053-7d0d-490f-bcf3-415139164895) Signup Form Headers: ![Image](https://github.com/user-attachments/assets/524cfebd-56fa-4fb9-a09c-fe3f1feeaaae) The payload is sent correctly, and the headers are properly set: ![Image](https://github.com/user-attachments/assets/3b99c365-94d9-48e2-9b01-2a468d381882) However, no response is received after submission: ![Image](https://github.com/user-attachments/assets/03aaaa84-423e-412e-bbb6-7ece7a4414ce) Testing the same URL and payload in Postman works fine. Need Help: What could be causing the request to work in Postman but not in my Next.js app? Any insights would be appreciated! ### What version of Better Auth are you using? 1.1.16 ### Provide environment information ```bash Operating System: Platform: win32 Arch: x64 Version: Windows 11 Pro Available memory (MB): 49078 Available CPU cores: 12 Binaries: Node: 20.13.1 npm: 10.5.2 Yarn: 1.22.21 pnpm: N/A Relevant Packages: next: 15.1.6 // Latest available version is detected (15.1.6). eslint-config-next: 15.1.6 react: 19.0.0 react-dom: 19.0.0 typescript: 5.7.3 Next.js Config: output: N/A ``` ### Which area(s) are affected? (Select all that apply) Client ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth"; export const auth = betterAuth({ emailAndPassword: { enabled: true, }, }); ``` ### Additional context _No response_
GiteaMirror added the lockedbug labels 2026-04-17 16:27:17 -05:00
Author
Owner

@mxurice-rm commented on GitHub (Feb 9, 2025):

Hi, I have exactly the same problem. Have you found a solution by any chance?

<!-- gh-comment-id:2646552173 --> @mxurice-rm commented on GitHub (Feb 9, 2025): Hi, I have exactly the same problem. Have you found a solution by any chance?
Author
Owner

@F-47 commented on GitHub (Feb 9, 2025):

@mxurice-rm I haven't found a solution yet. I tried creating a new Vite app and testing it in a clean environment, but the issue persists. I also attempted using both fetch and axios to call the API, but the problem remains the same.

<!-- gh-comment-id:2646562134 --> @F-47 commented on GitHub (Feb 9, 2025): @mxurice-rm I haven't found a solution yet. I tried creating a new Vite app and testing it in a clean environment, but the issue persists. I also attempted using both fetch and axios to call the API, but the problem remains the same.
Author
Owner

@mxurice-rm commented on GitHub (Feb 9, 2025):

@F-47 Okay. I also tried adding the OpenAPI plugin, which should be accessible via /auth/api/reference, but the same problems there too. I asked on the Discord if this is a known problem and if there are any solutions.

<!-- gh-comment-id:2646563974 --> @mxurice-rm commented on GitHub (Feb 9, 2025): @F-47 Okay. I also tried adding the OpenAPI plugin, which should be accessible via /auth/api/reference, but the same problems there too. I asked on the Discord if this is a known problem and if there are any solutions.
Author
Owner

@Bekacru commented on GitHub (Feb 9, 2025):

Since it's failing only in the browser, it's most likely related to CORS. Check that, especially since you're using a production URL on the client. I'm not sure why that's the case if you're developing locally.

<!-- gh-comment-id:2646576436 --> @Bekacru commented on GitHub (Feb 9, 2025): Since it's failing only in the browser, it's most likely related to CORS. Check that, especially since you're using a production URL on the client. I'm not sure why that's the case if you're developing locally.
Author
Owner

@F-47 commented on GitHub (Feb 9, 2025):

Update: I found the solution! The issue was in the backend (NestJS).

Here's my corrected code:

const app = await NestFactory.create<NestExpressApplication>(AppModule);
const expressApp = app.getHttpAdapter().getInstance();
expressApp.all("/api/auth/*", toNodeHandler(auth));

// The missing line that fixed the issue:
expressApp.use(express.json());

I had forgotten to include express.json(), and adding it resolved the problem. Everything is working perfectly now! 🎉

<!-- gh-comment-id:2646599724 --> @F-47 commented on GitHub (Feb 9, 2025): Update: I found the solution! The issue was in the backend (NestJS). Here's my corrected code: ```ts const app = await NestFactory.create<NestExpressApplication>(AppModule); const expressApp = app.getHttpAdapter().getInstance(); expressApp.all("/api/auth/*", toNodeHandler(auth)); // The missing line that fixed the issue: expressApp.use(express.json()); ``` I had forgotten to include express.json(), and adding it resolved the problem. Everything is working perfectly now! 🎉
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#26051