File size: 428 Bytes
d42edea | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | import mongoose from 'mongoose';
import bcrypt from 'bcrypt';
const UserSchema = new mongoose.Schema({
username: { type: String, required: true, unique: true },
password: { type: String, required: true },
});
UserSchema.pre('save', async function (next) {
if (!this.isModified('password')) return next();
this.password = await bcrypt.hash(this.password, 10);
next();
});
export = mongoose.model('User', UserSchema); |