Skip to content

Commit

Permalink
Merge branch 'master' of github.com:bnoguchi/everyauth
Browse files Browse the repository at this point in the history
  • Loading branch information
bnoguchi committed Apr 22, 2012
2 parents 591f5b4 + 607ab9e commit 55056c0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,17 @@ everyauth.everymodule.findUserById( function (userId, callback) {
});
```

If you need access to the request object the function can have three arguments:

```javascript
everyauth.everymodule.findUserById( function (req, userId, callback) {

// use the request in some way ...

// callback has the signature, function (err, user) {...}
});
```

Once you have configured this method, you now have access to the user object
that was fetched anywhere in your server app code as `req.user`. For instance:

Expand Down
12 changes: 10 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ everyauth.middleware = function () {
if (!auth || !auth.userId) return next();
var everymodule = everyauth.everymodule;
var pause = __pause(req);
everymodule.findUserById()(auth.userId, function (err, user) {

var findUserById_callback = function (err, user) {
if (err) {
pause.resume();
return next(err);
Expand All @@ -89,7 +90,14 @@ everyauth.middleware = function () {
else delete sess.auth;
next();
pause.resume();
});
};

var findUserById_function = everymodule.findUserById();

findUserById_function.length === 3
? findUserById_function( req, auth.userId, findUserById_callback )
: findUserById_function( auth.userId, findUserById_callback );

}
, connect.router(function (app) {
var modules = everyauth.enabled
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/everymodule.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ everyModule
, moduleErrback: 'THE error callback that is invoked any time an error occurs in the module; ' +
'defaults to `throw` wrapper'
, logoutRedirectPath: 'Where to redirect the app upon logging out'
, findUserById: 'function for fetching a user by his/her id -- used to assign to `req.user` - function (userId, callback) where function callback (err, user)'
, findUserById: 'function for fetching a user by his/her id -- used to assign to `req.user` - function ( [req], userId, callback) where function callback (err, user)'
, performRedirect: 'function for redirecting responses'
, userPkey: 'identifying property of the user; defaults to "id"'
})
Expand Down

0 comments on commit 55056c0

Please sign in to comment.