Guest User

Untitled

a guest
Oct 21st, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. const mongoose = require('mongoose');
  2. const bcrypt = require('bcryptjs');
  3.  
  4. const UserSchema = new mongoose.Schema({
  5. name: {
  6. type: String,
  7. required: true
  8. },
  9. email: {
  10. type: String,
  11. unique: true,
  12. required: true,
  13. lowercase: true
  14. },
  15. password: {
  16. type: String,
  17. required: true,
  18. select: false
  19. },
  20. createAt: {
  21. type: Date,
  22. default: Date.now
  23. }
  24.  
  25. })
  26.  
  27. UserSchema.pre('save', async function (next) {
  28. const hash = await bcrypt.hash(this.password, 10);
  29. this.password = hash;
  30.  
  31. next();
  32. })
  33.  
  34.  
  35.  
  36. const User = mongoose.model('User', UserSchema);
  37.  
  38. module.exports = User;
Add Comment
Please, Sign In to add comment