Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const mongoose = require('mongoose');
- const bcrypt = require('bcryptjs');
- const userSchema = new mongoose.Schema({
- username: {type: String, required: true},
- password: {type: String, required: true}
- });
- userSchema.pre('save', function(next){
- if (!this.isModified('password')) { return next() };
- bcrypt.hash(this.password, 10)
- .then(digest => {
- this.password = digest;
- next();
- });
- })
- const User = mongoose.model('User', userSchema);
- module.exports = User;
Add Comment
Please, Sign In to add comment