preserve auth headers in json proxies

This commit is contained in:
2569718930@qq.com
2026-06-11 14:04:17 +08:00
parent 5b65da6049
commit d314aa04d7
8 changed files with 59 additions and 16 deletions
@@ -1,5 +1,5 @@
import { NextRequest, NextResponse } from "next/server";
import { applyAuthResponseCookies, buildBackendRequestHeaders } from "@/lib/backend-auth";
import { applyAuthResponseCookies, buildBackendRequestHeaders, buildJsonBackendRequestHeaders } from "@/lib/backend-auth";
import { buildProxyExceptionResponse } from "@/lib/api-proxy";
import { requireOpsProxyAuth } from "@/lib/ops-proxy-auth";
@@ -14,9 +14,9 @@ export async function POST(req: NextRequest) {
if (authError) return authError;
const body = await req.text();
const headers: Record<string, string> = { ...auth.headers as Record<string, string>, "Content-Type": "application/json" };
const headers = buildJsonBackendRequestHeaders(auth.headers);
if (ENTITLEMENT_TOKEN) {
headers.Authorization = `Bearer ${ENTITLEMENT_TOKEN}`;
headers.set("Authorization", `Bearer ${ENTITLEMENT_TOKEN}`);
}
const res = await fetch(`${API_BASE}/api/ops/subscriptions/extend`, {
method: "POST", headers, body, cache: "no-store",
@@ -2,6 +2,7 @@ import { NextRequest, NextResponse } from "next/server";
import {
applyAuthResponseCookies,
buildBackendRequestHeaders,
buildJsonBackendRequestHeaders,
} from "@/lib/backend-auth";
import { buildProxyExceptionResponse } from "@/lib/api-proxy";
import { requireOpsProxyAuth } from "@/lib/ops-proxy-auth";
@@ -166,7 +167,7 @@ export async function POST(req: NextRequest) {
const res = await fetch(`${API_BASE}/api/ops/subscriptions/grant`, {
method: "POST",
headers: { ...(auth.headers as Record<string, string>), "Content-Type": "application/json" },
headers: buildJsonBackendRequestHeaders(auth.headers),
body,
cache: "no-store",
});