function requirePermission
requirePermission(permission: Permission): <R extends string>(
ctx: AuthContext<R>,
next: Next
) => Promise<void>

Returns a middleware that requires the caller to hold permission. It must run after authMiddleware, as in router.patch(path, authMiddleware, requirePermission("user:manage"), …). The returned middleware throws an APIException (403) when the caller lacks the permission.

Parameters

permission: Permission

Return Type

<R extends string>(
ctx: AuthContext<R>,
next: Next
) => Promise<void>

Usage

import { requirePermission } from "api/middleware/auth.ts";