interface user {
email: string,
password: string
}
const userSchema = new Schema({
email: {
type: String,
required: true,
lowercase: true,
unique: true
},
password: {
type: String,
requried: true
}
});
userSchema.pre('save', async function(next) {
try {
const salt = await bcrypt.genSalt(10);
const hashedPassword = await bcrypt.hash(this.password, salt);
this.password = hashedPassword;
next();
} catch (e) {
console.error(e.message);
}
});