BaseURL not being set when using client.setConfig
Description
Hello! Im using the generated client on my nextjs frontend, at the layout component (a component that is used by every page) we set the client config, but when trying to query data from my API, the base url is not being set, instead the query is made to localhost:3000
Reproducible example or configuration
Client frontend configuration:
useLayoutEffect(() => {
const token = Cookies.get("auth_token");
if (token) {
login(token);
}
if (!configSetRef.current && typeof token !== "undefined") {
console.log("setting config");
client.setConfig({
baseURL: "https://example.com",
headers: {
Authorization: `Bearer ${token}`,
},
});
}
}, [token]);
(the frontend log shows the setting config log and I logged the getConfig response, and the baseURL is set)
SDK Generation config:
// generate sdk
await createClient({
client: {
bundle: true,
name: "@hey-api/client-axios",
},
input: "docs/openapi.json",
output: "docs/sdk",
services: {
asClass: true,
name: "{{name}}",
},
});
OpenAPI specification (optional)
No response
System information (optional)
No response
@byeze in your client.setConfig example, where does client come from?
Are you able to fork a StackBlitz example and recreate the issue?
same
same issue, I continue to get this error:
code: 'ERR_INVALID_URL',
input: '/v1/integrations/abc/'
}
when I just use the client in my server action requests, like this won't work to set the base URL even though I've done it in layout. To make it work, I would have to do it manually:
await createTasks({
client,
body: {
title,
tasks,
},
});
But weirdly, everything works when running dev mode, its just when you build and run or in production it breaks.
Hey all, if someone can create a reproducible example, that would be the easiest way to debug what's going on
@mrlubos is the client instance supposed to work only on the client and not with server actions e.g. setting up the config async using "use server" and then importing it into a server action and using it?
I'm thinking that is probably the most straightforward reason why it could be an issue for me.
Sorry I couldn't create a reproducible example.
The base url property is named baseUrl with a lowercase 'rl' I believe so the docs maybe incorrect
@mbenniston that depends on the client used. Axios uses baseURL, Fetch API uses baseUrl
Ah nvm then docs look good
Hey all, I've got a solution for Next.js https://hey-api-docs-git-feat-client-api-hey-api.vercel.app/openapi-ts/clients/fetch#runtime-api
It's effectively the same as being able to define your own client instance inside sdk.gen.ts. I've tested it with Next.js and can confirm it solves the issues mentioned above.