fix oidc callback behind reverse proxy

This commit is contained in:
2026-06-16 10:01:13 +08:00
parent 9024f80a70
commit 626b8928f4
5 changed files with 78 additions and 3 deletions

26
proxy.test.ts Normal file
View File

@@ -0,0 +1,26 @@
import { describe, expect, test } from "bun:test";
import { NextRequest } from "next/server";
import { buildPublicRequestUrl } from "./proxy";
describe("public request URL", () => {
test("uses NEXTAUTH_URL for OIDC callback URLs behind Docker reverse proxies", () => {
const request = new NextRequest("http://0.0.0.0:8019/logs?range=7d");
expect(
buildPublicRequestUrl(request, {
NEXTAUTH_URL: "https://analytics.example.com",
}).href
).toBe("https://analytics.example.com/logs?range=7d");
});
test("falls back to forwarded proxy headers when no public URL is configured", () => {
const request = new NextRequest("http://0.0.0.0:8019/", {
headers: {
"x-forwarded-host": "analytics.example.com",
"x-forwarded-proto": "https",
},
});
expect(buildPublicRequestUrl(request).href).toBe("https://analytics.example.com/");
});
});