-
Notifications
You must be signed in to change notification settings - Fork 142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for adding custom decorators to endpoints #36
Comments
Where does permissions come from? Is it a guard? |
@doug-martin Permissions will be read from |
I was wondering if The reason I ask is without more context it is hard to answer your question. If it were my project I would try to make a new |
Again, without more information this is hard to answer. |
This is for @Injectable()
export class GqlAuthGuard implements CanActivate {
constructor(
private readonly reflector: Reflector,
private readonly userService: UserService,
) {}
async canActivate(context: ExecutionContext): Promise<boolean> {
const ctx = GqlExecutionContext.create(context).getContext();
const user = ctx.req.user as User;
if (!this.userService.canAccess(user)) {
return false;
}
const permissions = this.reflector.get<string[]>(
PermissionsMetaKey,
context.getHandler(),
);
const grantedPermissions = user.grantedPermissions;
if (grantedPermissions.some(gp => permissions.some(p => p === gp.name))) {
return true;
}
return false;
}
} And this is for import { SetMetadata } from '@nestjs/common';
export const PermissionsMetaKey = 'permissions';
export const Permissions = (permissions: string[]) =>
SetMetadata(PermissionsMetaKey, permissions); |
@doug-martin In |
* [ADDED] `decorators` option to resolver options to allow providing custom decorators to endpoints #36
* [ADDED] `decorators` option to resolver options to allow providing custom decorators to endpoints #36
Published under |
@doug-martin Thank you very much. You're awesome |
@doug-martin
I found that the library has support for adding filters, pipes, guards, but I don't know if I want to add
@Permissions(['READ', 'UPDATE'])
to built-in endpoints. Like what I did for custom methods:The text was updated successfully, but these errors were encountered: