@auth0/nextjs-auth0
Version:
Auth0 Next.js SDK
64 lines (63 loc) • 2.49 kB
TypeScript
import type { NextRequest } from "next/server.js";
import type { VerifyCredentialBody } from "../types/mfa.js";
/**
* Extracts Bearer token from Authorization header.
*
* @param req - NextRequest with Authorization header
* @returns Bearer token value
* @throws {InvalidRequestError} If header is missing or invalid format
*/
export declare function extractBearerToken(req: NextRequest): string;
/**
* Extracts MFA token from query param or Authorization header.
* Prioritizes query param (SDK client pattern), falls back to header (API pattern).
*
* @param req - NextRequest with mfa_token query param or Authorization header
* @returns MFA token value
* @throws {InvalidRequestError} If token is missing from both locations
*/
export declare function extractMfaToken(req: NextRequest): string;
/**
* Validates that a field is a non-empty string.
*
* @param value - Value to validate
* @param fieldName - Field name for error messages
* @returns Validated string value
* @throws {InvalidRequestError} If value is not a non-empty string
*/
export declare function validateStringFieldAndThrow(value: unknown, fieldName: string): string;
/**
* Validates that a field is a non-empty array.
*
* @param value - Value to validate
* @param fieldName - Field name for error messages
* @returns Validated array
* @throws {InvalidRequestError} If value is not a non-empty array
*/
export declare function validateArrayFieldAndThrow(value: unknown, fieldName: string): string[];
/**
* Validates that request body contains at least one verification credential.
* Credentials are: otp, oobCode+bindingCode, or recoveryCode.
*
* @param body - Request body to validate
* @returns Validated credential body
* @throws {InvalidRequestError} If no valid credential present
*/
export declare function validateVerificationCredentialAndThrow(body: unknown): VerifyCredentialBody;
/**
* Extracts path parameter from URL pathname.
*
* @param pathname - Request URL pathname
* @param paramName - Parameter name for error messages
* @returns Extracted parameter value
* @throws {InvalidRequestError} If parameter is missing
*/
export declare function extractPathParam(pathname: string, paramName: string): string;
/**
* Parses JSON from request body with error handling.
*
* @param req - NextRequest to parse
* @returns Parsed JSON body
* @throws {InvalidRequestError} If JSON is malformed
*/
export declare function parseJsonBody(req: NextRequest): Promise<unknown>;