Guest User

Untitled

a guest
Nov 8th, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. // User.js (model file)
  2. const conn = require('./conn');
  3. const bcrypt = require('bcrypt');
  4. const saltRounds = 12;
  5.  
  6. const User = conn.define('user', {
  7. id: {
  8. type: conn.Sequelize.UUID,
  9. defaultValue: conn.Sequelize.UUIDV4,
  10. primaryKey: true
  11. },
  12. firstName: {
  13. type: conn.Sequelize.STRING,
  14. allowNull: false,
  15. validate: {
  16. notEmpty: true
  17. }
  18. },
  19. lastName: {
  20. type: conn.Sequelize.STRING,
  21. allowNull: false,
  22. validate: {
  23. notEmpty: true
  24. }
  25. },
  26. username: {
  27. type: conn.Sequelize.STRING,
  28. allowNull: false,
  29. validate: {
  30. notEmpty: true
  31. }
  32. },
  33. password: {
  34. type: conn.Sequelize.STRING,
  35. allowNull: false,
  36. validate: {
  37. notEmpty: true
  38. }
  39. }
  40. });
  41.  
  42.  
  43. User.beforeSave(user => {
  44. return bcrypt.hash(user.password, saltRounds)
  45. .then(hash => user.password = hash)
  46. .catch(error => console.log(error))
  47. });
Add Comment
Please, Sign In to add comment