我将 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}
}
}