Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // User.js (model file)
- const conn = require('./conn');
- const bcrypt = require('bcrypt');
- const saltRounds = 12;
- const User = conn.define('user', {
- id: {
- type: conn.Sequelize.UUID,
- defaultValue: conn.Sequelize.UUIDV4,
- primaryKey: true
- },
- firstName: {
- type: conn.Sequelize.STRING,
- allowNull: false,
- validate: {
- notEmpty: true
- }
- },
- lastName: {
- type: conn.Sequelize.STRING,
- allowNull: false,
- validate: {
- notEmpty: true
- }
- },
- username: {
- type: conn.Sequelize.STRING,
- allowNull: false,
- validate: {
- notEmpty: true
- }
- },
- password: {
- type: conn.Sequelize.STRING,
- allowNull: false,
- validate: {
- notEmpty: true
- }
- }
- });
- User.beforeSave(user => {
- return bcrypt.hash(user.password, saltRounds)
- .then(hash => user.password = hash)
- .catch(error => console.log(error))
- });
Add Comment
Please, Sign In to add comment