import type { ClerkClient } from '@clerk/backend'; import type { AuthenticateRequestOptions, ClerkRequest, RedirectFun, SignedInAuthObject, SignedOutAuthObject } from '@clerk/backend/internal'; import type { NextMiddleware, NextRequest } from 'next/server'; import type { AuthFn } from '../app-router/server/auth'; import { type ContentSecurityPolicyOptions } from './content-security-policy'; import type { FrontendApiProxyOptions, NextMiddlewareEvtParam, NextMiddlewareRequestParam, NextMiddlewareReturn } from './types'; export type ClerkMiddlewareSessionAuthObject = (SignedInAuthObject | SignedOutAuthObject) & { redirectToSignIn: RedirectFun; redirectToSignUp: RedirectFun; }; export type ClerkMiddlewareAuth = AuthFn; type ClerkMiddlewareHandler = (auth: ClerkMiddlewareAuth, request: NextMiddlewareRequestParam, event: NextMiddlewareEvtParam) => NextMiddlewareReturn; type AuthenticateAnyRequestOptions = Omit; /** * The `clerkMiddleware()` function accepts an optional object. The following options are available. * @interface */ export interface ClerkMiddlewareOptions extends AuthenticateAnyRequestOptions { /** * If true, additional debug information will be logged to the console. */ debug?: boolean; /** * When set, automatically injects a Content-Security-Policy header(s) compatible with Clerk. */ contentSecurityPolicy?: ContentSecurityPolicyOptions; /** * When set, enables the middleware to proxy Frontend API requests to Clerk. * This is useful when direct communication with Clerk's API is blocked. */ frontendApiProxy?: FrontendApiProxyOptions; } type ClerkMiddlewareOptionsCallback = (req: NextRequest) => ClerkMiddlewareOptions | Promise; /** * Middleware for Next.js that handles authentication and authorization with Clerk. * For more details, please refer to the docs: https://clerk.com/docs/reference/nextjs/clerk-middleware */ interface ClerkMiddleware { /** * @example * export default clerkMiddleware((auth, request, event) => { ... }, options); */ (handler: ClerkMiddlewareHandler, options?: ClerkMiddlewareOptions): NextMiddleware; /** * @example * export default clerkMiddleware((auth, request, event) => { ... }, (req) => options); */ (handler: ClerkMiddlewareHandler, options?: ClerkMiddlewareOptionsCallback): NextMiddleware; /** * @example * export default clerkMiddleware(options); */ (options?: ClerkMiddlewareOptions): NextMiddleware; /** * @example * export default clerkMiddleware; */ (request: NextMiddlewareRequestParam, event: NextMiddlewareEvtParam): NextMiddlewareReturn; } /** * The `clerkMiddleware()` helper integrates Clerk authentication into your Next.js application through Middleware. `clerkMiddleware()` is compatible with both the App and Pages routers. */ export declare const clerkMiddleware: ClerkMiddleware; type AuthenticateRequest = Pick['authenticateRequest']; export declare const createAuthenticateRequestOptions: (clerkRequest: ClerkRequest, options: ClerkMiddlewareOptions) => Parameters[1]; export {}; //# sourceMappingURL=clerkMiddleware.d.ts.map