Skip to main content
Deno 2 is finally here 🎉️
Learn more

basic_auth v1.1.0

Module for performing Basic Auth in Deno Deploy.

Demo

Usage

import basicAuth function from the module url and use it like the below:

import { basicAuth } from "https://deno.land/x/basic_auth@v1.1.0/mod.ts";

addEventListener("fetch", (e) => {
  const unauthorized = basicAuth(e.request, "Access to my site", {
    "user": "password",
  });
  if (unauthorized) {
    e.respondWith(unauthorized);
    return;
  }
  e.respondWith(new Response("You are authorized!"));
});

Replace user and password part with your credentials. You can also set multiple credentials by setting multiple key value pairs in the 3rd parameter.

API doc

LICENSE

MIT