How to use the @nestjs/graphql.GqlExecutionContext function in @nestjs/graphql

To help you get started, we’ve selected a few @nestjs/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 notadd / nt-module-user / package / auth / auth.guard.js View on Github external
async canActivate(context) {
        const gqlCtx = graphql_1.GqlExecutionContext.create(context);
        const req = gqlCtx.getContext().req;
        const operationName = gqlCtx.getInfo().fieldName;
        const token = req.headers.authorization;
        const user = await this.authService.validateUser(token, operationName);
        gqlCtx.getContext().user = user;
        if (user && user.username === 'sadmin')
            return true;
        const userPerm = [];
        if (user && user.roles.length) {
            user.roles.forEach(role => {
                if (role.permissions && role.permissions.length) {
                    role.permissions.forEach(permission => {
                        userPerm.push(permission.identify);
                    });
                }
            });
github notadd / nt-module-user / package / auth / auth.gurad.js View on Github external
async canActivate(context) {
        const gqlCtx = graphql_1.GqlExecutionContext.create(context);
        const user = gqlCtx.getContext().user;
        if (user && user.username === 'sadmin')
            return true;
        const userPerm = [];
        if (user && user.roles.length) {
            user.roles.forEach(role => {
                if (role.permissions && role.permissions.length) {
                    role.permissions.forEach(permission => {
                        userPerm.push(permission.identify);
                    });
                }
            });
        }
        const handlerPerm = Reflect.getMetadata(decorators_1.PERMISSION_DEFINITION, context.getClass().prototype, context.getHandler().name);
        if (handlerPerm && !userPerm.includes(handlerPerm.identify)) {
            return false;