Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// @flow
import bcrypt from "bcryptjs";
import util from "util";
import { Response, ErrorResponse } from "@webiny/api/graphql/commodo";
import { JwtToken } from "../../authentication/jwtToken";
type GetModel = (context: Object) => Function;
const verifyPassword = util.promisify(bcrypt.compare);
const invalidCredentials = new ErrorResponse({
code: "INVALID_CREDENTIALS",
message: "Invalid credentials."
});
export default (getModel: GetModel) => async (root: any, args: Object, context: Object) => {
const User = getModel(context);
const user: User = (await User.findOne({
query: { email: args.username }
}): any);
if (!user) {
return invalidCredentials;
}
// $FlowFixMe - user has a "password" attribute.