【问题标题】:NextAuth credentials not saving in stateNextAuth 凭据未保存在状态
【发布时间】:2021-05-17 21:25:18
【问题描述】:

我将 nextAuth 与我自己的用户数据库 (mongoDb) 一起使用,我希望此人能够使用他们的凭据登录。问题是我的用户对象没有保持状态,这似乎是 nextAuth 的人们不鼓励用户名和密码的设计选择,他们说:

If you use a custom credentials provider user accounts will not be 
persisted in a database by NextAuth.js (even if one is configured)

这似乎是一个巨大的障碍......我目前这样做是为了克服它,我想知道这里有什么缺点:

 async authorize(credentials) {

        // check if the user exists in the database
        let user = await db.collection('users').findOne({username:credentials.username})

        if (user && user.password == credentials.password) {
          // return the user object returned from the database
          // because next auth will not save this is state
          return {name: {user}}
        } else {
          return {name: null, email: null, image: null}
        }
      }

【问题讨论】:

    标签: reactjs next.js next-auth


    【解决方案1】:

    缺点是您必须自己管理将密码保存在数据库中的安全方面。

    我们通常推荐拥有经过实战考验的系统的第三方提供商来确保您的密码安全。如果您对推出自己的解决方案感到满意,那么它没有任何问题。

    作为警告说明⚠,仅从您上面的代码中,我已经看到了 HUGE 安全问题。您似乎将密码作为纯文本存储在数据库中。如果您的数据库被泄露,您的所有用户帐户将立即可供黑客使用。

    【讨论】:

      猜你喜欢
      • 2022-01-16
      • 1970-01-01
      • 2015-08-27
      • 1970-01-01
      • 1970-01-01
      • 2016-04-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多