import { verifyBasicAuth } from "https://deno.land/x/ayonli_jsext@v0.9.72/esm/http/util.js";
Performs basic authentication verification for the request. When passed, this
function returns nothing (undefined
), otherwise it returns a Response
with status 401 Unauthorized
, which should be responded to the client.
Examples
Example 1
Example 1
import { verifyBasicAuth, type BasicAuthorization } from "@ayonli/jsext/http";
const users = new Map([
["root", "pa$$w0rd"]
]);
async function verify(auth: BasicAuthorization) {
const password = users.get(auth.username);
return !!password && password === auth.password;
}
export default {
async fetch(req) {
const res = await verifyBasicAuth(req, verify);
if (res) {
return res;
}
// continue with the request
},
};