Merge pull request #372 from zitadel/custom-request-headers

feat: allow configuring custom request headers
This commit is contained in:
Elio Bischof
2025-02-21 14:06:50 +01:00
committed by GitHub
3 changed files with 23 additions and 1 deletions

View File

@@ -27,5 +27,11 @@ declare namespace NodeJS {
* Optional: wheter a user must have verified email
*/
EMAIL_VERIFICATION: string;
/**
* Optional: custom request headers to be added to every request
* Split by comma, key value pairs separated by colon
*/
CUSTOM_REQUEST_HEADERS: string;
}
}

View File

@@ -44,6 +44,21 @@ export async function createServiceForHost<T extends ServiceClass>(
const transport = createServerTransport(token, {
baseUrl: serviceUrl,
interceptors: !process.env.CUSTOM_REQUEST_HEADERS
? undefined
: [
(next) => {
return (req) => {
process.env.CUSTOM_REQUEST_HEADERS.split(",").forEach(
(header) => {
const kv = header.split(":");
req.header.set(kv[0], kv[1]);
},
);
return next(req);
};
},
],
});
return createClientFor<T>(service)(transport);

View File

@@ -12,7 +12,8 @@
"ZITADEL_API_URL",
"ZITADEL_SERVICE_USER_ID",
"ZITADEL_SERVICE_USER_TOKEN",
"NEXT_PUBLIC_BASE_PATH"
"NEXT_PUBLIC_BASE_PATH",
"CUSTOM_REQUEST_HEADERS"
],
"tasks": {
"generate": {