Untitled
unknown
plain_text
a year ago
498 B
2
Indexable
const mongoose = require('mongoose'); const bcrypt = require('bcrypt'); const userSchema = new mongoose.Schema({ username: { type: String, unique: true, required: true }, password: { type: String, required: true } }); userSchema.pre('save', async function (next) { const user = this; if (user.isModified('password')) { user.password = await bcrypt.hash(user.password, 10); } next(); }); const User = mongoose.model('User', userSchema); module.exports = User;
Editor is loading...
Leave a Comment