我创建了一个用户注册api并使用
passport-local-mongoose
库,现在,我正在创建一个播种机,所以我必须手动将密码存储在我的数据库中,我如何才能做到这一点?
这是我的注册api代码
api.post('/register', async (req, res) => {
const { username, email, password } = req.body
const account = await Account.findOne({ email })
if (account) {
res.status(409).send('Email already exist!')
return
}
await Account.register(new Account(
{
username: username ,
email: email,
role: 'player'
}),
req.body.password
);
passport.authenticate(
'local', {
session: false
}
)
res.status(201).send('Account Created!')
});
Account
是个模特