import { auth } from "https://deno.land/x/acorn@0.0.11/handlers.ts";
A handler which allows easy implementation of authorization for a route.
The auth
handler takes the content handler plus options which
includes an authorization handler.
Example
import { Router, immutable } from "https://deno.land/x/acorn/mod.ts";
const router = new Router();
router.all("/", auth(() => ({ hello: "acorn"}), {
authorize(ctx) {
if (
ctx.request.headers.get("authorization")?.toLowerCase() ===
"bearer 123456789"
) {
return true;
}
},
}));
router.listen({ port: 8080 });
Returns
RouteOptionsWithHandler<R, BodyType, Params, ResponseType>