feat: use hashPassword function
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import { DataTypes, Model, Optional } from 'sequelize';
|
import { DataTypes, Model, Optional } from 'sequelize';
|
||||||
import bcrypt from 'bcrypt';
|
import bcrypt from 'bcrypt';
|
||||||
import sequelize from '../db/config';
|
import sequelize from '../db/config';
|
||||||
|
import { hashPassword } from '../utils/auth';
|
||||||
|
|
||||||
interface UserAttributes {
|
interface UserAttributes {
|
||||||
id: number;
|
id: number;
|
||||||
@@ -47,8 +48,7 @@ User.init(
|
|||||||
hooks: {
|
hooks: {
|
||||||
beforeCreate: async (user: User) => {
|
beforeCreate: async (user: User) => {
|
||||||
if (user.password) {
|
if (user.password) {
|
||||||
const salt = await bcrypt.genSalt(10);
|
user.password = await hashPassword(user.password) as string;
|
||||||
user.password = await bcrypt.hash(user.password, salt);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user