NestJS module for Casbin using the TypeORM Adapter
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 { CasbinTypeormModule } from "nestjs-casbin-typeorm";
@Module({
imports: [
CasbinTypeormModule.forRootAsync(
{
dbConnectionOptions: { // typeORM connectionOptions
type: 'mysql',
host: 'MYSQL_HOST',
port: 'MYSQL_PORT',
username: 'MYSQL_USERNAME',
password: 'MYSQL_PASSWORD',
database: 'MYSQL_DATABASE',
},
modelPath: "src/model/roles.conf"
}
)
],
controllers: [AppController],
providers: [AppService]
})
export class AppModule {}
in YOUR_PROJECT_ROOT/src/app.service.ts
file:
import { Injectable } from "@nestjs/common";
import { CasbinService } from "nestjs-casbin-typeorm";
@Injectable()
export class AppService {
constructor(
private readonly casbinService: CasbinService
) {}
checkPermission(): boolean {
return this.casbinService.checkPermission("alice", "dataX", "read");
}
}
This project is MIT licensed.