@accounts/rest-express
Version:
Server side REST express middleware for accounts
29 lines • 1.17 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.changePassword = void 0;
const send_error_1 = require("../../utils/send-error");
const express_validator_1 = require("express-validator");
const matchOrTrow_1 = require("../../utils/matchOrTrow");
const changePassword = (accountsServer) => [
(0, express_validator_1.body)('oldPassword').isString().notEmpty(),
(0, express_validator_1.body)('newPassword').isString().notEmpty(),
async (req, res) => {
try {
const userId = req.userId;
if (!userId) {
res.status(401);
res.json({ message: 'Unauthorized' });
return;
}
const { oldPassword, newPassword } = (0, matchOrTrow_1.matchOrThrow)(req);
const accountsPassword = accountsServer.getServices().password;
await accountsPassword.changePassword(userId, oldPassword, newPassword);
res.json(null);
}
catch (err) {
(0, send_error_1.sendError)(res, err);
}
},
];
exports.changePassword = changePassword;
//# sourceMappingURL=change-password.js.map