diff --git a/src/auth/graphql/resolvers/resetPassword.js b/src/auth/graphql/resolvers/resetPassword.js index c3f266aadf..720243ffff 100644 --- a/src/auth/graphql/resolvers/resetPassword.js +++ b/src/auth/graphql/resolvers/resetPassword.js @@ -12,9 +12,9 @@ function resetPassword(collection) { api: 'GraphQL', }; - const token = await this.operations.collections.auth.resetPassword(options); + const result = await this.operations.collections.auth.resetPassword(options); - return token; + return result; } const resetPasswordResolver = resolver.bind(this); diff --git a/src/auth/operations/resetPassword.js b/src/auth/operations/resetPassword.js index a56e3100e9..49652ca093 100644 --- a/src/auth/operations/resetPassword.js +++ b/src/auth/operations/resetPassword.js @@ -100,7 +100,8 @@ async function resetPassword(args) { // 4. Return updated user // ///////////////////////////////////// - return token; + const fullUser = await this.findByID({ collection: collectionConfig.slug, id: user.id }); + return { token, user: fullUser }; } module.exports = resetPassword; diff --git a/src/auth/requestHandlers/resetPassword.js b/src/auth/requestHandlers/resetPassword.js index 769a01769b..d70245777c 100644 --- a/src/auth/requestHandlers/resetPassword.js +++ b/src/auth/requestHandlers/resetPassword.js @@ -2,7 +2,7 @@ const httpStatus = require('http-status'); async function resetPassword(req, res, next) { try { - const token = await this.operations.collections.auth.resetPassword({ + const result = await this.operations.collections.auth.resetPassword({ req, res, collection: req.collection, @@ -12,7 +12,8 @@ async function resetPassword(req, res, next) { return res.status(httpStatus.OK) .json({ message: 'Password reset successfully.', - token, + token: result.token, + user: result.user, }); } catch (error) { return next(error); diff --git a/src/collections/graphql/init.js b/src/collections/graphql/init.js index 850e4db2fd..dce238e8ad 100644 --- a/src/collections/graphql/init.js +++ b/src/collections/graphql/init.js @@ -250,7 +250,13 @@ function registerCollections() { }; this.Mutation.fields[`resetPassword${singularLabel}`] = { - type: GraphQLString, + type: new GraphQLObjectType({ + name: formatName(`${slug}ResetPassword`), + fields: { + token: { type: GraphQLString }, + user: { type: collection.graphQL.type }, + }, + }), args: { token: { type: GraphQLString }, password: { type: GraphQLString }, diff --git a/src/graphql/index.js b/src/graphql/index.js index ae265c5fe8..8702973e98 100644 --- a/src/graphql/index.js +++ b/src/graphql/index.js @@ -73,7 +73,7 @@ class InitializeGraphQL { } if (typeof this.config.graphQL.mutations === 'function') { - const customMutations = this.config.graphQL.mutations(this); + const customMutations = this.config.graphQL.mutations(GraphQL, this); this.Mutation = { ...this.Mutation, fields: {