nest-access-control icon indicating copy to clipboard operation
nest-access-control copied to clipboard

ForRootAsync is not working

Open raksrivastava opened this issue 3 years ago • 1 comments

ForRootAsync is not working. I have written it in app.module.ts.

   AccessControlModule.forRootAsync({
       inject: [RolePermissionsService],
      useFactory: async (roleService: RolePermissionsService): Promise<RolesBuilder> => {
        return new RolesBuilder(await roleService.getAll());
      },
    }), 

roleService.getAll() return result as below array.

 [
    { role: 'admin', resource: 'video', action: 'create:any', attributes: '*, !views' },
    { role: 'admin', resource: 'video', action: 'read:any', attributes: '*' },
    { role: 'admin', resource: 'video', action: 'update:any', attributes: '*, !views' },
    { role: 'admin', resource: 'video', action: 'delete:any', attributes: '*' },

    { role: 'user', resource: 'video', action: 'create:own', attributes: '*, !rating, !views' },
    { role: 'user', resource: 'video', action: 'read:any', attributes: '*' },
    { role: 'user', resource: 'video', action: 'update:own', attributes: '*, !rating, !views' },
    { role: 'user', resource: 'video', action: 'delete:own', attributes: '*' }
];

i am getting this error. image

raksrivastava avatar Nov 25 '22 14:11 raksrivastava

The error says it can't find the RolePermissionsService, do you have that service exported from other modules?

Revisit this part again: https://github.com/nestjsx/nest-access-control#forrootasync

shekohex avatar Nov 26 '22 20:11 shekohex