Node.js
0
Вклад в тег
var isAuthenticated = function (req, res, next) {
var currentUserId = req.user ? req.user.id : false;
if(!currentUserId){
res.redirect('/');
return;
}
Admin.findById(currentUserId,function (err, user) {
if(!user || user.role !== "admin"){
res.redirect('/');
}else{
next();
}
})
}
router.get('/admin', isAuthenticated, function(req, res, next) {
res.end();
});