Skip to main content
Module

x/basic_auth/mod.ts>basicAuth

Module for performing Basic Auth in Deno Deploy
Go to Latest
function basicAuth
import { basicAuth } from "https://deno.land/x/basic_auth@v1.0.2/mod.ts";

Authenticates the given request with the given user-password table. Returns unauthorized response if the request is not authenticated, otherwise returns undefined.

import { basicAuth } from "https://deno.land/x/basic_auth@v1.0.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!"));
});

Parameters

request: Request
realm: string
userPasswordTable: Record<string, string>

Returns

Response | undefined