diff --git a/README.md b/README.md index 84b476d..974c0a7 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ Pass a Basic auth header to the `parse()` method. If parsing fails ```js const { parse } = require('basic-auth'); -const user = parse(req.headers.authorization); +const user = parse(req.headers.authorization ?? ''); // => { name: 'something', pass: 'whatever' } ``` @@ -49,7 +49,7 @@ A header string from any other location can also be parsed for example a `Proxy- ```js const { parse } = require('basic-auth'); -const user = parse(req.getHeader('Proxy-Authorization')); +const user = parse(req.getHeader('Proxy-Authorization') ?? ''); ``` A credentials object can be formatted with `auth.format` as @@ -71,7 +71,7 @@ const compare = require('tsscmp'); // Create server const server = http.createServer(function (req, res) { - const credentials = parse(req.headers.authorization); + const credentials = parse(req.headers.authorization ?? ''); // Check credentials // The "check" function will typically be against your user store