Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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