Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在带有passport的Express NodeJS服务器中确保ReadMin问题_Javascript_Node.js_Express_Login_Server - Fatal编程技术网

Javascript 在带有passport的Express NodeJS服务器中确保ReadMin问题

Javascript 在带有passport的Express NodeJS服务器中确保ReadMin问题,javascript,node.js,express,login,server,Javascript,Node.js,Express,Login,Server,我知道有以下功能: 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.");

我知道有以下功能:

  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”的用户—该用户,并且只有该用户才能访问任何受EnsureReadmin保护的路由。

您的条件是:要确保页面仅由管理员访问,他是名为admin的用户。只需将角色属性添加到您的用户,并改用它,但我作为管理员登录,它不允许我访问该页面。。。