apolloapi-v2/src/store/api/auth/authChangePassword.js
2022-04-22 16:36:06 +02:00

18 lines
508 B
JavaScript

module.exports = ({ define }) => {
define('changePassword', async ({ password }, { knex, errors, utils }) => {
// TODO transaction
const [ setup ] = await knex('setup').select('*').limit(1)
if (!setup) {
throw new errors.AuthorizationError('Setup not finished')
}
await knex('setup').update({
password: await utils.auth.hashPassword(password)
})
utils.auth.changeSystemPassword(password)
utils.auth.changeNodeRpcPassword(password)
}, {
auth: true
})
}