Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
});
}
});
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;