You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This works well for simple cases like setting a static baseUrl. However, in server-side multi-tenant applications (e.g. a Next.js app serving multiple brands), the client configuration depends on per-request data that requires async operations:
Base URL varies per brand — determined by the incoming request hostname (requires await headers() in Next.js App Router)
Auth token varies per session — fetched from an auth provider at request time (inherently async)
Current workaround
Since createClientConfig can't be async, the runtimeConfigPath feature is unusable for this scenario. Instead, we create a fresh client per request in a manual wrapper:
Alternatively, a different mechanism that supports per-request configuration in server-side contexts would work too — for example, a clientProvider pattern or middleware-style hook that runs before each request.
Use case summary
Requirement
Why async is needed
Multi-tenant base URL
Brand is derived from request hostname (await headers() in Next.js)
Per-request auth token
Token is fetched from auth provider at request time
SSR / Server Components
Next.js App Router server components require async access to request context
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Problem
When using
@hey-api/client-fetchwithruntimeConfigPath, the exportedcreateClientConfigfunction is synchronous:This works well for simple cases like setting a static
baseUrl. However, in server-side multi-tenant applications (e.g. a Next.js app serving multiple brands), the client configuration depends on per-request data that requires async operations:await headers()in Next.js App Router)Current workaround
Since
createClientConfigcan't be async, theruntimeConfigPathfeature is unusable for this scenario. Instead, we create a fresh client per request in a manual wrapper:Then every SDK call needs the client passed explicitly:
This works, but it means:
clientexported fromclient.gen.tsis never usedruntimeConfigPathfeature provides no value{ client }Proposal
It would be great if
createClientConfigcould optionally be async:Alternatively, a different mechanism that supports per-request configuration in server-side contexts would work too — for example, a
clientProviderpattern or middleware-style hook that runs before each request.Use case summary
await headers()in Next.js)Related
createClientConfigblocking server-side per-request configuration.Thanks for the great library! Happy to discuss alternative approaches.
All reactions