Rehash password for admin-user pwd updates (#398)

resolved #397
This commit is contained in:
Timothy Carambat 2023-11-27 12:47:07 -06:00 committed by GitHub
parent 29d3c603f2
commit 55d319b527
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -21,6 +21,14 @@ const User = {
update: async function (userId, updates = {}) {
try {
// Rehash new password if it exists as update
// will be given to us as plaintext.
if (updates.hasOwnProperty("password") && updates.password.length >= 8) {
updates.password = bcrypt.hashSync(updates.password, 10);
} else {
delete updates.password;
}
await prisma.users.update({
where: { id: parseInt(userId) },
data: updates,