This commit is contained in:
Michele Marcucci 2018-11-06 10:19:55 +01:00
commit 2dbcfe297c
3 changed files with 36 additions and 1 deletions

View File

@ -1,6 +1,6 @@
const config = require('config')
module.exports = {
client: 'pg',
client: 'sqlite',
connection: config.get('db.url')
}

View File

@ -0,0 +1,21 @@
module.exports.typeDefs = `
type AuthActions {
changePassword (input: AuthChangePasswordInput!): AuthChangePasswordOutput!
}
input AuthChangePasswordInput {
password: String!
}
type AuthChangePasswordOutput {
error: Error
}
`
module.exports.resolvers = {
AuthActions: {
changePassword (root, args, { dispatch }) {
return dispatch('api/auth/changePassword', args.input)
}
}
}

View File

@ -0,0 +1,14 @@
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)
})
}, {
auth: true
})
}