-
-
Notifications
You must be signed in to change notification settings - Fork 529
Request body is omitted from POST requests in Next.js #2111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi @corydeppen, I haven't tried using Next 14 but I haven't encountered this issue with Next 15. Could you provide a minimal reproducible example? |
@kerwanp After digging some more, my issue seems to be related to how |
I recognize it doesn't exist today, but would it be feasible in the future to pass the options directly to |
I also face the issue with Server function/action in Next.js 14, but not in Next.js 15. Will try to make a reproducible repo. |
I’m facing this issue in Next.js 15 as well. Interestingly, it only occurs in production builds (next build && next start) and not during development. For POST requests, I had to pass a custom fetch function that explicitly sets "Content-Type": "application/json" and includes my Authorization headers for protected routes. Additionally, I ran into issues with the next cache options in fetch for GET requests—these options were being omitted. I was able to work around this by explicitly passing fetch to the client call: const { data } = await client.GET('/api/products', {
fetch
}); This allowed the fetch + caching logic to work as expected. While this workaround works for now, it's not ideal. It would be great to understand whether this is a limitation of openapi-fetch or if there’s a way to handle this more cleanly in production. Has anyone found a better solution? |
I just requested an update to the docs however perhaps this helps with your issues as well: #2242 My proposal and simple setup still allows for auth middleware as well. |
openapi-fetch version
0.13.4
Description
I'm trying to use openapi-fetch in a Next.js 14 app and I've noticed the
body
is being omitted fromPOST
requests made from within server functions and RSCs. Specifically, prior to callingnew CustomRequest()
,requestInit.body
contains the expected serialized/stringified object, however it's missing from therequest
instance that's created.Admittedly, I haven't tried this in a different framework yet, so I'm not entirely sure whether this could be related to Next.js at this point. I just wanted to include that context in case it helps.
Reproduction
Make a
POST
request from a server function or RSC and observe the API request will be made without abody
.Expected result
Fetch requests containing a
body
that are made via openapi-fetch should pass the serialized data to the API as a standard fetch request would.Extra
The text was updated successfully, but these errors were encountered: