@auth0/nextjs-auth0
Version:
Auth0 Next.js SDK
43 lines (42 loc) • 1.89 kB
TypeScript
import { NextRequest } from "next/server.js";
import { ProxyOptions } from "../types/index.js";
/**
* Securely builds a Headers object for forwarding a NextRequest via fetch.
*
* This function:
* 1. Uses a strict **allow-list** (DEFAULT_HEADER_ALLOW_LIST).
* 2. Strips all hop-by-hop headers as defined by https://datatracker.ietf.org/doc/html/rfc2616#section-13.5.1.
*
* @param request The incoming NextRequest object.
* @returns A WHATWG Headers object suitable for `fetch`.
*/
export declare function buildForwardedRequestHeaders(request: NextRequest): Headers;
/**
* Securely builds a Headers object for forwarding a fetch response.
*
* This function:
* 1. Strips all hop-by-hop headers as defined by https://datatracker.ietf.org/doc/html/rfc2616#section-13.5.1.
*
* @param request The incoming Response object.
* @returns A WHATWG Headers object suitable for `fetch`.
*/
export declare function buildForwardedResponseHeaders(response: Response): Headers;
/**
* Builds a URL representing the upstream target for a proxied request.
*
* This function correctly handles the path transformation by:
* 1. Extracting the path segment that comes AFTER the proxyPath
* 2. Intelligently combining it with targetBaseUrl to avoid path segment duplication
*
* Example:
* - proxyPath: "/me"
* - targetBaseUrl: "https://issuer/me/v1"
* - incoming: "/me/v1/some-endpoint"
* - remaining path: "/v1/some-endpoint" (after removing "/me")
* - result: "https://issuer/me/v1/some-endpoint" (no /v1 duplication)
*
* @param req - The incoming request to mirror when constructing the target URL.
* @param options - Proxy configuration containing the base URL and proxy path.
* @returns A URL object pointing to the resolved target endpoint with forwarded query parameters.
*/
export declare function transformTargetUrl(req: NextRequest, options: ProxyOptions): URL;