【发布时间】:2014-11-20 17:29:39
【问题描述】:
我知道有以下功能:
function ensureAdmin(req, res, next) {
if (req.user && req.user.username === "admin") {
return next();
} else {
res.send("You do not have access to this web page. Please, contact to the system administrator.");
}
为了确保页面只能由管理员访问。但是,我在任何地方都找不到如何成为管理员用户。我不知道是否值得知道,但我正在使用 MongoDB。
【问题讨论】:
-
你的条件是:保证一个页面只能被“admin”访问(他是一个名为“admin”的用户)。只需将角色属性添加到您的用户并使用它
-
但我以“管理员”身份登录,它不允许我访问该页面...
标签: javascript node.js express login server