开发者

How to monkey patch request obj with data in express/connect

Helllo Im programming a middleware library to abstract the process of oauth authorize/authenticate and supply own authentication strategies.

I'm stuck because when I monkey patch the request with data it won't be available on any routed request but the other middlewares (connect/express documentat开发者_如何学Goion is very poor on this subject).

How can I make the data stick so it would be available to every request (except for static files)?

Thanks.

P.s I don't use other available modules because it was just frustrating to make them work...


Try this:

function authOrDie() {
  return function(req,res,next) {
    console.log(req.isAuthenticated());
    next(); // Have to call next to continue to the next middleware
  };
}

I assume console.log(req.isAuthenticated()); is being run and it's working, I also assume it's printing false.

Also, if requests to your static files doesn't need to be authenticated you should move it much higher in the stack.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜