Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 261946a

Browse files
committed
fix: correct examples in readme
1 parent ee2a6dd commit 261946a

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

README.md

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,34 @@ app.use(couchdbProxy(function(req) {
4747

4848
In CouchDB, users are represented with a user context object. These are simply objects with `name` and `roles` fields. Usually this information comes from a document in the `_users` database, however we can also generate it from other means.
4949

50-
This library allows you to complete asynchronous authentication lookup, return a promise or pass `next` as the third argument. If you do use the `next()` callback, you absolutely must call it, or the request will never complete.
50+
This library allows you to complete asynchronous authentication lookups. The simple version to return a Promise.
5151

5252
```js
53-
app.use(couchdbProxy(function(req, res, next) {
53+
app.use(couchdbProxy(function(req, res) {
54+
const token = req.get("Authorization");
55+
56+
return validateToken(token).then(function(user) {
57+
return {
58+
name: user.name,
59+
roles: []
60+
};
61+
});
62+
}));
63+
```
64+
65+
Of course, you can also go with the more traditional `next` style callback that Express uses. If you do use the `next()` callback, you absolutely must call it, or the request will never complete.
66+
67+
```js
68+
app.use(couchdbProxy(function(req, res) {
5469
const token = req.get("Authorization");
5570

5671
validateToken(token, function(err, user) {
5772
if (err) return next(err);
5873

59-
return {
74+
next(null, {
6075
name: user.name,
6176
roles: []
62-
};
77+
});
6378
});
6479
}));
6580
```

0 commit comments

Comments
 (0)