import { auth } from "https://deno.land/x/acorn@0.7.1/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.
Examples
Example 1
Example 1
import { Router, immutable } from "jsr:@oak/acorn/";
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 });
Parameters
handler: RouteHandler<ResponseType, BodyType, Params>
options: AuthOptions<R, BodyType, Params>