FindbyUsername 总是返回 undefined

编程入门 行业动态 更新时间:2024-10-04 11:16:27

<a href=https://www.elefans.com/category/jswz/34/990471.html style=FindbyUsername 总是返回 undefined"/>

FindbyUsername 总是返回 undefined

我正在尝试使用护照本地策略实施登录和注销。该策略是运行一个函数来检查是否存在具有该用户名的用户,然后继续使用 passport 和 bcrypt 登录。 除了用于登录的帖子路线外,其他所有东西都有效


// passport local strategy setup
   `passport.use(
      new LocalStrategy((username, password, done) => {
        const user = du.findByUsername;
    // return error if an error found
    // if user does not exist
        if (!user) {
          console.log("user does not exist");
          return done(null, false, { message: "user does not exist" });
        }
`
    // use bcrypt to compare passwords
        `const match = bcryptpare(password, user.pword);
        if(!match) {
          console.log("Incorrect password");
          return done(null, false, { message: "Incorrect password" });
        }
        console.log("success");
        return done(null, user);
      })
    );`


// ROUTES


    `router.post(
     ["/users/login", "/users/:id"],
      passport.authenticate("local", {
        failureRedirect: "/users/login",
      }),
`
   redirect to see all prdoucts upon login
     ` db.getAllProducts
    )`;




    module.exports = router;




   here is the findbyUsername that always retruns undefined
Note that in the database, the password is stored in the pword column


    const findByUsername = (name) => {
      pool.query(
        "SELECT * FROM users WHERE username = $1",
        [name],
        (error, results) => {
          if (error) {
            throw error;
          }
          return results.rows;
        }
      );
    };
    ` 
回答如下:

更多推荐

FindbyUsername 总是返回 undefined

本文发布于:2024-05-30 18:13:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1770780.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:FindbyUsername   undefined

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!