fix(profile): make save button work and verify current password
This commit is contained in:
@@ -4467,6 +4467,10 @@ app.put('/api/users/:id/profile', requireAuth, async (req, res) => {
|
||||
let hash = null;
|
||||
if (req.body?.password) {
|
||||
if (String(req.body.password).length < 6) return res.status(400).json({ error: 'Пароль должен быть не короче 6 символов' });
|
||||
const oldPassword = String(req.body?.old_password || '');
|
||||
if (!oldPassword) return res.status(400).json({ error: 'Введите текущий пароль' });
|
||||
const oldOk = await bcrypt.compare(oldPassword, target.password_hash);
|
||||
if (!oldOk) return res.status(400).json({ error: 'Неверный текущий пароль' });
|
||||
hash = await bcrypt.hash(String(req.body.password), 10);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user