veloze
Version:
A modern and fast express-like webserver for the web
43 lines (31 loc) • 1.08 kB
Markdown
[◀︎ core/HttpError](../core/HttpError.md)
[🛖](../index.md)
[](../middleware/bodyParser.md)
Checks basic-authorization.
In case that username is known then middleware chain is processed with username
being part of `req.auth.username`.
Otherwise HTTP 401 Unauthorized is thrown.
```js
import { Router, basicAuth } from "veloze";
const app = new Router();
app.get(
"/",
basicAuth({
users: { foo: "bar", me: "secret" }, // define allowed users
realm: "Secured Area", // optional realm name
}),
(req, res) => {
const { username } = req.auth;
res.end();
}
);
```
| type | property | description |
| ------ | ---------------- | ---------------------------------------------------------------- |
| object | users | object with usernames as keys and plain text passwords as values |
| string | \[realm=Secure\] | realm name |
---
[🔝 TOP](