ensures reset password sends back a new user
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 },
|
||||
|
||||
@@ -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: {
|
||||
|
||||
Reference in New Issue
Block a user