简体   繁体   English

带有护照的Express NodeJS服务器中的sureAdmin问题

[英]ensureAdmin issue in an Express NodeJS server with passport

I know there's the following function: 我知道有以下功能:

  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.");
    }

in order to ensure a page is only accessed by the admin. 为了确保页面仅由管理员访问。 However, I don't find anywhere how to become a user to admin. 但是,我找不到任何地方可以成为管理员用户。 I don't know if it is worthwhile to know, but I am using MongoDB. 我不知道是否值得了解,但是我正在使用MongoDB。

Your middleware is checking a user's username to see if it is an admin. 您的中间件正在检查用户的用户名,看它是否是管理员。

If you want to create an admin user, in this case, you'll want to create a user whose username is 'admin' -- that user, and only that user, will be able to access any of the ensureAdmin protected routes. 如果要创建一个管理员用户,在这种情况下,您将要创建一个用户名为“ admin”的用户-该用户(只有该用户)将能够访问任何受ensureAdmin保护的路由。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM