每当向后端发出获取用户的请求时,我都会使用散列密码返回该用户。
{
"_id": "5e4e3e7eecd9a53c185117d4",
"username": "rick",
"email": "rick@gmail.com",
"password": "$2b$10$/eD8g4jCw6Bx0.FNxFDADO5tc70AvUmK0H/7R/0JTyo2q9PcGAdOO",
"createdAt": "2020-02-20T08:08:30.878Z",
"updatedAt": "2020-02-20T08:08:30.878Z",
"__v": 0
}
Run Code Online (Sandbox Code Playgroud)
用户模型
const userSchema = new Schema({
username: { type: String, required: true },
email: { type: String, required: true },
password: { type: String, required: true },
posts: [{
type: mongoose.Schema.Types.ObjectId,
ref: "Post"
}]
}, { timestamps: true })
Run Code Online (Sandbox Code Playgroud)
列出用户路由
listUsers: (req, res) => {
User.find{}, (err, users) => {
if (err) {
return res.status(500).json({ error: "Server error occurred" })
} else if …Run Code Online (Sandbox Code Playgroud)