我创建了一个用户注册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
是一个模型