sequelize-bcrypt
Installation
npm i sequelize-bcrypt
Setup
const { Sequelize, DataTypes } = require('sequelize');
const useBcrypt = require('sequelize-bcrypt');
const database = new Sequelize({
...sequelizeConnectionOptions,
});
const User = database.define('User', {
email: { type: DataTypes.STRING },
password: { type: DataTypes.STRING },
});
useBcrypt(User, options);
Options
{
field: 'password',
rounds: 12,
compare: 'authenticate',
}
Usage
User.create({ email: 'john.doe@example.com', password: 'SuperSecret!' });
const user = await User.findOne({ where: { email: 'john.doe@example.com' } });
user.authenticate('WrongPassword!');
user.authenticate('SuperSecret!');