Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix checkBadrequest useless logic in user-permissions' graphql config #5625

Merged
merged 2 commits into from
Mar 27, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 18 additions & 13 deletions packages/strapi-plugin-users-permissions/config/schema.graphql.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ const _ = require('lodash');
* @throws ApolloError if the body is a bad request
*/
function checkBadRequest(contextBody) {
if (_.get(contextBody, 'output.payload.statusCode', 200) !== 200) {
const statusCode = _.get(contextBody, 'output.payload.statusCode', 400);
const message = _.get(contextBody, 'output.payload.message', 'Bad Request');
throw new Error(message, statusCode, _.omit(contextBody, ['output']));
if (_.get(contextBody, 'statusCode', 200) !== 200) {
const message = _.get(contextBody, 'error', 'Bad Request');
const exception = new Error(message);
exception.code = _.get(contextBody, 'statusCode', 400);
exception.data = contextBody;
throw exception;
}
}

Expand Down Expand Up @@ -44,7 +46,7 @@ module.exports = {
jwt: String!
user: UsersPermissionsMe!
}

type ForgotPassword {
ok: Boolean
}
Expand Down Expand Up @@ -218,9 +220,9 @@ module.exports = {
checkBadRequest(output);

return {
ok: output.ok || output
ok: output.ok || output,
};
}
},
},
changePassword: {
description: 'Change your password based on a code',
Expand All @@ -235,27 +237,30 @@ module.exports = {

return {
user: output.user || output,
jwt: output.jwt
jwt: output.jwt,
};
}
},
},
emailConfirmation: {
description: 'Confirm an email users email address',
resolverOf: 'plugins::users-permissions.auth.emailConfirmation',
resolver: async (obj, options, { context }) => {
context.query = _.toPlainObject(options);

await strapi.plugins['users-permissions'].controllers.auth.emailConfirmation(context, true);
await strapi.plugins['users-permissions'].controllers.auth.emailConfirmation(
context,
true
);
let output = context.body.toJSON ? context.body.toJSON() : context.body;

checkBadRequest(output);

return {
user: output.user || output,
jwt: output.jwt
jwt: output.jwt,
};
}
}
},
},
},
},
};