Replies: 2 comments 2 replies
-
I would use an app like Proxyman to inspect what the actual request is for both. |
Beta Was this translation helpful? Give feedback.
-
So I am here with an update. The request works if I pass the fetch function that Next.js polyfills. const res = await ky.post("auth/native", {
fetch, // added line that fixes the issue
json: credentials,
prefixUrl: `${env("baseUrl")}/api/rest/v1`,
headers: {
APIKey: env("apiKey") ?? "",
},
}); Unfortunately, I cannot add this to the whole API client that I am creating since this throws an error when used in browser environment. So I had to create a special instance for the server like so: export const publicApi = ky.extend({
prefixUrl: `${env("baseUrl")}/api/rest/v1`,
hooks: {
beforeRequest: [attachApiKeyHook],
},
});
export const ssrPublicApi = publicApi.extend({ fetch }); This is quite annoying since I would have to keep double the amount of api instances, If anyone knows a better solution please share it with me. |
Beta Was this translation helpful? Give feedback.
-
Hi, I have defined a route in Next.js 13 where I fetch external API. However an identical request fails with ky but works with fetch, what could I be doing wrong here?
I am using the app router and
ky-universal
. The error message from the external API says that the email and password is undefined in the request body. However, when I check the request in the catch block, it does have both fields set correctly.The request using ky:
The request using fetch:
Beta Was this translation helpful? Give feedback.
All reactions