Guest User

Untitled

a guest
Jun 23rd, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. // ./users/User.js
  2.  
  3. const mongoose = require('mongoose');
  4. const bcrypt = require('bcrypt');
  5.  
  6. const userSchema = new mongoose.Schema({
  7. username: {
  8. type: String,
  9. unique: true,
  10. },
  11. password: String,
  12. });
  13.  
  14. userSchema.pre('save', function() {
  15. bcrypt
  16. .hash(this.password, 10)
  17. .then(hash => {
  18. this.password = hash;
  19.  
  20. next();
  21. })
  22. .catch(err => {
  23. console.log(err);
  24. });
  25. });
  26.  
  27. module.exports = mongoose.model('User', userSchema);
Add Comment
Please, Sign In to add comment