hey-api / openapi-ts

✨ Turn your OpenAPI specification into a beautiful TypeScript client
https://heyapi.vercel.app
Other
1.03k stars 86 forks source link

BaseURL not being set when using client.setConfig #1028

Open byeze opened 1 week ago

byeze commented 1 week ago

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

mrlubos commented 1 week ago

@byeze in your client.setConfig example, where does client come from?

Are you able to fork a StackBlitz example and recreate the issue?