fix graphql forgot password

This commit is contained in:
Dan Ribbens
2020-04-23 13:11:01 -04:00
parent 6658c368a0
commit 9ee2679211
6 changed files with 19 additions and 17 deletions

View File

@@ -13,12 +13,8 @@ const registerUpload = require('../uploads/graphql/register');
const buildWhereInputType = require('./schema/buildWhereInputType');
class GraphQL {
constructor(config, collections, User, Upload, globals) {
this.config = config;
this.User = User;
this.Upload = Upload;
this.collections = collections;
this.globals = globals;
constructor(init) {
Object.assign(this, init);
this.init = this.init.bind(this);
this.types = {

View File

@@ -60,7 +60,7 @@ class Payload {
identifyAPI('GraphQL'),
createAuthHeaderFromCookie,
authenticate,
new GraphQL(this.config, this.collections, this.User, this.Upload, this.globals).init(),
new GraphQL(this).init(),
);
this.router.get(this.config.routes.graphQLPlayground, graphQLPlayground({

View File

@@ -168,7 +168,7 @@ function registerUser() {
args: {
[useAsUsername]: { type: new GraphQLNonNull(GraphQLString) },
},
resolve: forgotPassword(this.User, this.email),
resolve: forgotPassword(this.config, this.User.Model, this.sendEmail),
};
this.Mutation.fields.resetPassword = {

View File

@@ -1,17 +1,18 @@
/* eslint-disable no-param-reassign */
const { forgotPassword } = require('../../operations');
const forgotPasswordResolver = (config, email) => async (_, args, context) => {
const forgotPasswordResolver = (config, Model, email) => async (_, args, context) => {
const options = {
config,
Model,
data: args,
email,
req: context,
};
const result = await forgotPassword(options);
await forgotPassword(options);
return result;
return true;
};
module.exports = forgotPasswordResolver;

View File

@@ -67,12 +67,6 @@ const forgotPassword = async (args) => {
if (typeof afterForgotPasswordHook === 'function') {
await afterForgotPasswordHook(options);
}
// /////////////////////////////////////
// 4. Return
// /////////////////////////////////////
return;
} catch (error) {
throw error;
}

View File

@@ -29,6 +29,17 @@ const sanitizeUserCollection = (userConfig) => {
sanitizedUserConfig.fields = sanitizeFields(userConfig.fields);
// /////////////////////////////////
// Hidden fields
// /////////////////////////////////
const hiddenFields = Array.isArray(sanitizedUserConfig.hidden) ? sanitizedUserConfig.hidden : [];
sanitizedUserConfig.hidden = [
...hiddenFields,
'resetPasswordToken',
'resetPasswordExpiration',
];
return sanitizedUserConfig;
};