Advertisement
Guest User

Untitled

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