From 380e86b88563e41a86020224c0a7162b2c9f8daa Mon Sep 17 00:00:00 2001 From: yiekheng Date: Sun, 3 May 2026 08:27:32 +0800 Subject: [PATCH] feat(web): WebAuthn relying-party helper (host-derived rpID/origin) --- web/lib/auth-rp.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 web/lib/auth-rp.ts diff --git a/web/lib/auth-rp.ts b/web/lib/auth-rp.ts new file mode 100644 index 0000000..d0d5cbe --- /dev/null +++ b/web/lib/auth-rp.ts @@ -0,0 +1,21 @@ +import "server-only"; +import { headers } from "next/headers"; + +export type RpInfo = { + rpID: string; + origin: string; + rpName: string; +}; + +export async function getRpInfo(): Promise { + const hdrs = await headers(); + const host = hdrs.get("x-forwarded-host") ?? hdrs.get("host") ?? "localhost:8010"; + const rpID = host.split(":")[0]; + const proto = hdrs.get("x-forwarded-proto") ?? "http"; + const origin = `${proto}://${host}`; + return { + rpID, + origin, + rpName: "CM Bot V2", + }; +}