UNPKG

@lock-dev/geo-block

Version:

Geographic blocking module for lock.dev security framework

47 lines (46 loc) 1.2 kB
export interface EdgeGeoBlockConfig { /** * Mode of operation - allow only specified countries or block specified countries * @default 'blocklist' */ mode: 'allowlist' | 'blocklist'; /** * List of country codes to allow or block (ISO 3166-1 alpha-2) * @example ['US', 'CA', 'GB'] */ countries: string[]; /** * HTTP status code to return when blocked * @default 403 */ blockStatusCode?: number; /** * Message to return when blocked * @default 'Access denied based on your location' */ blockMessage?: string; /** * URL to redirect to when blocked (optional) */ redirectUrl?: string; } /** * Create an edge-compatible geo-blocking middleware for Next.js * * @example * ```typescript * // middleware.ts * import { createEdgeGeoBlock } from '@lock.dev/geo-block/edge'; * * export default createEdgeGeoBlock({ * mode: 'blocklist', * countries: ['RU', 'BY'], * blockStatusCode: 451 * }); * * export const config = { * matcher: '/api/:path*', * }; * ``` */ export declare function createEdgeGeoBlock(config: EdgeGeoBlockConfig): (request: any) => Response | undefined;