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

To help you get started, we’ve selected a few @webiny/commodo-graphql 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 / loginUsingIdToken.js View on Github external
// @flow
import { Response, ErrorResponse } from "@webiny/commodo-graphql";
import generateJWT from "../generateJWT";
type GetModelType = (context: Object) => Function;

const invalidCredentials = new ErrorResponse({
    code: "INVALID_CREDENTIALS",
    message: "Invalid credentials."
});

export default (getModel: GetModelType) => async (root: any, args: Object, context: Object) => {
    const SecurityUser = getModel(context);

    // Decode the login token
    let user;
    try {
        const authPlugin = context.plugins
            .byType("security-authentication-provider")
            .filter(pl => pl.hasOwnProperty("getUser"))
            .pop();

        user = await authPlugin.getUser({ idToken: args.idToken, SecurityUser }, context);