Open wa12rior opened 1 year ago
Anyone?
don't know the exact reason I faced the same issue.
the json payload sent to one of the backend service from route handler was empty.
I did headers: { 'content-type': 'application/json', 'content-length': JSON.stringify(values).length + '' },
and it worked for me too.
It's definitely has to do something related to nextjs's wrap around the fetch (to handle cache) which is globally available. But thanks for your workaround here.
@mabdullahadeel No problem. Although this is workaround I found a way to do it in beforeRequest hook to avoid unnecessary code duplication.
hooks: {
beforeRequest: [
(request, options) => {
request.headers.set('Content-Type', 'application/json');
if (options.body) {
request.headers.set('Content-Length', options.body.length);
}
},
],
},
I'm using nextjs 13 with new app router and next-auth. My authorize method in CredentialsProvider looks like this:
Here is the body of the loginUser method
And server gets empty request payload because header
content-length
is empty (""). When I add it manually it suddenly works.headers: { 'content-type': 'application/json', 'content-length': JSON.stringify(values).length + '' },
Does someone knows why that is happening?