Skip to main content
Module

x/acorn/handlers.ts>auth

A focused RESTful server framework for Deno 🌰🦕
Latest
function auth
import { auth } from "https://deno.land/x/acorn@0.5.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

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 });

Type Parameters

R extends string
BodyType
Params extends RouteParameters<R>
ResponseType