diff --git a/knexfile.js b/knexfile.js index d705eae..1759fee 100644 --- a/knexfile.js +++ b/knexfile.js @@ -1,6 +1,6 @@ const config = require('config') module.exports = { - client: 'pg', + client: 'sqlite', connection: config.get('db.url') } diff --git a/src/graphql/graphqlModules/Auth/AuthChangePassword.js b/src/graphql/graphqlModules/Auth/AuthChangePassword.js new file mode 100644 index 0000000..faa7dfb --- /dev/null +++ b/src/graphql/graphqlModules/Auth/AuthChangePassword.js @@ -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) + } + } +} \ No newline at end of file diff --git a/src/store/api/auth/authChangePassword.js b/src/store/api/auth/authChangePassword.js new file mode 100644 index 0000000..a281f1c --- /dev/null +++ b/src/store/api/auth/authChangePassword.js @@ -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 + }) +}