ensures reset password sends back a new user

This commit is contained in:
James
2020-10-01 14:57:59 -04:00
parent 96c1362a5d
commit 3359cd4e9b
5 changed files with 15 additions and 7 deletions

View File

@@ -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);

View File

@@ -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;

View File

@@ -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);

View File

@@ -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 },

View File

@@ -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: {