UNPKG

@clerk/nextjs

Version:

Clerk SDK for NextJS

58 lines 2.65 kB
import type { AuthObject, ClerkClient } from '@clerk/backend'; import type { AuthenticateRequestOptions, ClerkRequest, RedirectFun } from '@clerk/backend/internal'; import type { NextMiddleware, NextRequest } from 'next/server'; import type { AuthProtect } from './protect'; import type { NextMiddlewareEvtParam, NextMiddlewareRequestParam, NextMiddlewareReturn } from './types'; export type ClerkMiddlewareAuthObject = AuthObject & { redirectToSignIn: RedirectFun<Response>; }; export interface ClerkMiddlewareAuth { (): Promise<ClerkMiddlewareAuthObject>; protect: AuthProtect; } type ClerkMiddlewareHandler = (auth: ClerkMiddlewareAuth, request: NextMiddlewareRequestParam, event: NextMiddlewareEvtParam) => NextMiddlewareReturn; /** * The `clerkMiddleware()` function accepts an optional object. The following options are available. * @interface */ export type ClerkMiddlewareOptions = AuthenticateRequestOptions & { /** * If true, additional debug information will be logged to the console. */ debug?: boolean; }; type ClerkMiddlewareOptionsCallback = (req: NextRequest) => ClerkMiddlewareOptions; /** * Middleware for Next.js that handles authentication and authorization with Clerk. * For more details, please refer to the docs: https://clerk.com/docs/references/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<ClerkClient, 'authenticateRequest'>['authenticateRequest']; export declare const createAuthenticateRequestOptions: (clerkRequest: ClerkRequest, options: ClerkMiddlewareOptions) => Parameters<AuthenticateRequest>[1]; export {}; //# sourceMappingURL=clerkMiddleware.d.ts.map