I'm trying to create a guard that takes parameters and also uses a global service (prismaService).
The dependency injection works as expected for a normal guard, but to create a guard that accepts parameters I'm using mixins.
export const UserGuard = (table: Prisma.ModelName, field: string) => {
class RoleGuardMixin implements CanActivate {
constructor(prismaService: PrismaService) {}
async canActivate(context: ExecutionContext) {
const subject = await this.prismaService[table];
return true;
}
}
const guard = mixin(RoleGuardMixin);
return guard;
};
In this case the PrismaService isn't found (I believe because the mixin is a pure function that returns a class). Is there a way to get nestjs to inject PrismaService after the guard is called? Can services be injected into classes?