Files
community-rule/lib/server/redirectWithRequestId.ts
adilallo a725cf1a32 Spend login, invite, and email-change links only after a confirm POST so mail scanners cannot use them up.
GET still shows a one-button page, a used invitation can resend or reopen for the signed-in invitee, and an email-change GET no longer signs the account out.
2026-11-22 16:58:30 -07:00

15 lines
453 B
TypeScript

import { NextRequest, NextResponse } from "next/server";
import { REQUEST_ID_HEADER } from "./requestId";
import { getPublicOrigin } from "./publicOrigin";
export function redirectWithRequestId(
request: NextRequest,
path: string,
requestId: string,
status: 303 | 307 = 307,
): NextResponse {
const res = NextResponse.redirect(new URL(path, getPublicOrigin(request)), status);
res.headers.set(REQUEST_ID_HEADER, requestId);
return res;
}