How to use the @webiny/api/graphql/commodo.ErrorResponse function in @webiny/api

To help you get started, we’ve selected a few @webiny/api examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github webiny / webiny-js / packages / api-security / src / plugins / graphql / userResolvers / loginUser.js View on Github external
// @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.