You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12345678910111213141516171819202122232425262728293031323334353637383940
  1. const mongoose = require('mongoose')
  2. const userSchema = new mongoose.Schema({
  3. name: {
  4. type: String
  5. },
  6. email: {
  7. type: String,
  8. required: true
  9. },
  10. password: {
  11. type: String,
  12. required: true
  13. },
  14. role: {
  15. type: String
  16. },
  17. tokens: [{
  18. token: {
  19. type: String,
  20. required: true
  21. }
  22. }]
  23. })
  24. // userSchema.pre('save', async function(next) {
  25. // const user = this
  26. // console.log('pre hash: ' + user.password)
  27. // user.password = await bcrypt.hash(user.password, 8)
  28. // console.log('posle hash: ' + user.password)
  29. // console.log('Middleware before password hash')
  30. // next()
  31. // })
  32. const User = mongoose.model('User', userSchema)
  33. module.exports = User