basic-auth-for-vercel-middleware
v1.0.8
Published
Basic Authentication for vercel middleware
Downloads
296
Maintainers
Readme
Basic Authentication for vercel middleware
Installation
npm install --save basic-auth-for-vercel-middleware
yarn add basic-auth-for-vercel-middleware
Usage
add "PROJECT_ROOT/middleware.(js | ts)"
directory structure:
├── ...
├── middleware.js
└── ...
edit "PROJECT_ROOT/middleware.(js | ts)"
like
import { createBasicAuthHandler } from "basic-auth-for-vercel-middleware";
export default createBasicAuthHandler({ name: "test", password: "test" });
//if you use matcher
/*
export const config = {
matcher: "/",
};
*/
import { createBasicAuthHandler } from "basic-auth-for-vercel-middleware";
export default createBasicAuthHandler(
{ name: "test", password: "test" },
"message for auth"
);
//3rd parameter is skip flag(function or boolean)
import { createBasicAuthHandler } from "basic-auth-for-vercel-middleware";
export default createBasicAuthHandler(
{ name: "test", password: "test" },
"message for auth",
(request) =>
request.headers.get("user-agent")?.includes("user-agent-for-cdn-robot")
);