@reinaldooli/nest-casbin
    TypeScript icon, indicating that this package has built-in type declarations

    0.1.8 • Public • Published

    nest-casbin

    Make magic with Nest.js, Casbin and TypeORM.

    Example

    In YOUR_PROJECT_ROOT/src/app.module.ts file:

    import { Module } from "@nestjs/common";
    import { AppController } from "./app.controller";
    import { AppService } from "./app.service";
    import { CasbinModule } from "@pardjs/nest-casbin";
     
    @Module({
      imports: [
        CasbinModule.forRootAsync(
          {
            type: "mysql",
            host: "localhost",
            port: 3306,
            username: "root",
            password: "",
            database: "casbin"
          },
          "/path/to/the/casbin/model/file.conf"
        )
      ],
      controllers: [AppController],
      providers: [AppService]
    })
    export class AppModule {}

    in ``YOUR_PROJECT_ROOT/src/app.service.ts` file:

    import { Injectable, Inject } from "@nestjs/common";
    import { Enforcer } from "casbin";
    import { CASBIN_ENFORCER, CasbinService } from "@pardjs/nest-casbin";
     
    @Injectable()
    export class AppService {
      constructor(
        @Inject(CASBIN_ENFORCER) private readonly enforcer: Enforcer,
        private readonly casbinService: CasbinService
      ) {}
     
      getHello(): string {
        return this.casbinService.checkPermission("alice", "data1", "read");
      }
    }

    Install

    npm i @reinaldooli/nest-casbin

    DownloadsWeekly Downloads

    19

    Version

    0.1.8

    License

    MIT

    Unpacked Size

    21.5 kB

    Total Files

    20

    Last publish

    Collaborators

    • k1ng