Skip to content

Commit 301fe41

Browse files
authored
Add string fallback to README examples (#108)
1 parent 0ea09f3 commit 301fe41

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

‎README.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ Pass a Basic auth header to the `parse()` method. If parsing fails
4141

4242
```js
4343
const { parse } = require('basic-auth');
44-
const user = parse(req.headers.authorization);
44+
const user = parse(req.headers.authorization ?? '');
4545
// => { name: 'something', pass: 'whatever' }
4646
```
4747
4848
A header string from any other location can also be parsed for example a `Proxy-Authorization` header:
4949
5050
```js
5151
const { parse } = require('basic-auth');
52-
const user = parse(req.getHeader('Proxy-Authorization'));
52+
const user = parse(req.getHeader('Proxy-Authorization') ?? '');
5353
```
5454
5555
A credentials object can be formatted with `auth.format` as
@@ -71,7 +71,7 @@ const compare = require('tsscmp');
7171

7272
// Create server
7373
const server = http.createServer(function (req, res) {
74-
const credentials = parse(req.headers.authorization);
74+
const credentials = parse(req.headers.authorization ?? '');
7575

7676
// Check credentials
7777
// The "check" function will typically be against your user store

0 commit comments

Comments
 (0)