Guest User

Untitled

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