DRY req props that depend on auth (fix #6727) (#6731)

* DRY req props that depend on auth (fix #6727)

authentication leads to req.loggedIn and req.uid being set. However, a
later authentication event might outdate them. Here, I create one
function for setting those properties, and make sure it also is called
on the `action:middleware.authenticate` hook, which would be such an
authentication event. If there are other places, those should be added
as well.

* fix lint errors

* fix lint error

* change exports
This commit is contained in:
LudwikJaniuk
2018-09-04 15:43:33 +02:00
committed by Barış Soner Uşaklı
parent 3e1b007f9f
commit c7f3b76b4e
3 changed files with 20 additions and 16 deletions

View File

@@ -8,6 +8,8 @@ var user = require('../user');
var privileges = require('../privileges');
var plugins = require('../plugins');
var auth = require('../routes/authentication');
var controllers = {
helpers: require('../controllers/helpers'),
};
@@ -22,7 +24,9 @@ module.exports = function (middleware) {
return plugins.fireHook('action:middleware.authenticate', {
req: req,
res: res,
next: next,
next: function (err) {
auth.setAuthVars(req, res, function () { next(err); });
},
});
}