mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 20:47:32 +00:00
fix: use custom req headers in all server requests
This commit is contained in:
2
apps/login/next-env-vars.d.ts
vendored
2
apps/login/next-env-vars.d.ts
vendored
@@ -28,6 +28,6 @@ declare namespace NodeJS {
|
|||||||
* Optional: custom request headers to be added to every request
|
* Optional: custom request headers to be added to every request
|
||||||
* Split by comma, key value pairs separated by colon
|
* Split by comma, key value pairs separated by colon
|
||||||
*/
|
*/
|
||||||
CUSTOM_REQUEST_HEADERS: string;
|
CUSTOM_REQUEST_HEADERS?: string;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
"use server";
|
"use server";
|
||||||
|
|
||||||
import { createServerTransport } from "@zitadel/client/node";
|
import { createServerTransport } from "./zitadel";
|
||||||
import { createUserServiceClient } from "@zitadel/client/v2";
|
import { createUserServiceClient } from "@zitadel/client/v2";
|
||||||
import { headers } from "next/headers";
|
import { headers } from "next/headers";
|
||||||
import { getSessionCookieById } from "./cookies";
|
import { getSessionCookieById } from "./cookies";
|
||||||
|
@@ -17,7 +17,7 @@ import {
|
|||||||
setUserPassword,
|
setUserPassword,
|
||||||
} from "@/lib/zitadel";
|
} from "@/lib/zitadel";
|
||||||
import { ConnectError, create } from "@zitadel/client";
|
import { ConnectError, create } from "@zitadel/client";
|
||||||
import { createServerTransport } from "@zitadel/client/node";
|
import { createServerTransport } from "../zitadel";
|
||||||
import { createUserServiceClient } from "@zitadel/client/v2";
|
import { createUserServiceClient } from "@zitadel/client/v2";
|
||||||
import {
|
import {
|
||||||
Checks,
|
Checks,
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
import { createClientFor } from "@zitadel/client";
|
import { createClientFor } from "@zitadel/client";
|
||||||
import { createServerTransport } from "@zitadel/client/node";
|
import { createServerTransport } from "./zitadel";
|
||||||
import { IdentityProviderService } from "@zitadel/proto/zitadel/idp/v2/idp_service_pb";
|
import { IdentityProviderService } from "@zitadel/proto/zitadel/idp/v2/idp_service_pb";
|
||||||
import { OIDCService } from "@zitadel/proto/zitadel/oidc/v2/oidc_service_pb";
|
import { OIDCService } from "@zitadel/proto/zitadel/oidc/v2/oidc_service_pb";
|
||||||
import { OrganizationService } from "@zitadel/proto/zitadel/org/v2/org_service_pb";
|
import { OrganizationService } from "@zitadel/proto/zitadel/org/v2/org_service_pb";
|
||||||
@@ -50,7 +50,7 @@ export async function createServiceForHost<T extends ServiceClass>(
|
|||||||
: [
|
: [
|
||||||
(next) => {
|
(next) => {
|
||||||
return (req) => {
|
return (req) => {
|
||||||
process.env.CUSTOM_REQUEST_HEADERS.split(",").forEach(
|
process.env.CUSTOM_REQUEST_HEADERS!.split(",").forEach(
|
||||||
(header) => {
|
(header) => {
|
||||||
const kv = header.split(":");
|
const kv = header.split(":");
|
||||||
req.header.set(kv[0], kv[1]);
|
req.header.set(kv[0], kv[1]);
|
||||||
|
@@ -52,6 +52,8 @@ import {
|
|||||||
import { unstable_cacheLife as cacheLife } from "next/cache";
|
import { unstable_cacheLife as cacheLife } from "next/cache";
|
||||||
import { getUserAgent } from "./fingerprint";
|
import { getUserAgent } from "./fingerprint";
|
||||||
import { createServiceForHost } from "./service";
|
import { createServiceForHost } from "./service";
|
||||||
|
import { createServerTransport as libCreateServerTransport } from "@zitadel/client/node";
|
||||||
|
import { Transport } from '@connectrpc/connect';
|
||||||
|
|
||||||
const useCache = process.env.DEBUG !== "true";
|
const useCache = process.env.DEBUG !== "true";
|
||||||
|
|
||||||
@@ -1497,3 +1499,24 @@ export async function listAuthenticationMethodTypes({
|
|||||||
userId,
|
userId,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function createServerTransport(token: string, baseUrl: string): Transport {
|
||||||
|
return libCreateServerTransport(token, {
|
||||||
|
baseUrl,
|
||||||
|
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);
|
||||||
|
};
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user