Skip to content
Make magic with Nest.js, Casbin and TypeORM.
Branch: master
Clone or download
Latest commit a94db53 Feb 21, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.vscode chore: update settings Feb 21, 2019
dist
src
.gitignore feat: The basic design for this module. Feb 21, 2019
README.md feat: The basic design for this module. Feb 21, 2019
jest.config.js
package-lock.json
package.json 0.0.5 Feb 21, 2019
tsconfig.json
tslint.json

README.md

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");
  }
}
You can’t perform that action at this time.