Files
0pt/src/auth/require-order-owner.ts
T
admin a1557b2a7d
CI (SIAX Cloud) / integration (push) Has been skipped
masterplan-lock / check (push) Successful in 4s
CI (SIAX Cloud) / security (push) Successful in 14s
masterplan-lock / check (pull_request) Successful in 4s
CI (SIAX Cloud) / security (pull_request) Successful in 14s
Security Scan (SIAX Cloud) / security (push) Successful in 30s
CI (SIAX Cloud) / quality (push) Successful in 35s
CI (SIAX Cloud) / integration (pull_request) Successful in 25s
Security Scan (SIAX Cloud) / security (pull_request) Successful in 54s
CI (SIAX Cloud) / quality (pull_request) Successful in 1m31s
feat(payments): bind orders to verified tenant and buyer
2026-09-15 19:53:58 +02:00

21 lines
894 B
TypeScript

import { NextResponse, type NextRequest } from "next/server";
import { requireRouteAuth } from "./require-route-auth";
import type { OrderOwner } from "@/lib/orders-store";
export type OrderOwnerAuthResult =
| { response: NextResponse; owner?: never }
| { response?: never; owner: OrderOwner };
/** Payment/order routes require a real verified principal even in dev escape mode. */
export async function requireOrderOwner(req: NextRequest): Promise<OrderOwnerAuthResult> {
const auth = await requireRouteAuth(req);
if (auth.response) return { response: auth.response };
const principal = auth.ctx.principal;
if (!principal?.tenantId || !principal.sub) {
return {
response: NextResponse.json({ error: "OPT_UNAUTHENTICATED", message: "Verified buyer required" }, { status: 401 }),
};
}
return { owner: { tenantId: principal.tenantId, subject: principal.sub } };
}