Skip to main content
Module

x/acorn/handlers.ts>auth

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

Type Parameters

R extends string
BodyType
Params extends RouteParameters<R>
ResponseType