Skip to content
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
src
 
 
 
 
 
 
 
 
 
 

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");
  }
}

About

Make magic with Nest.js, Casbin and TypeORM.

Topics

Resources

Releases

No releases published

Packages

No packages published