Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/0xb4lamx/nestjs-casbin-typeorm

NestJS Casbin module with TypeORM Adapter
https://github.com/0xb4lamx/nestjs-casbin-typeorm

access-control casbin nestjs nestjs-casbin-typeorm typeorm-adapter

Last synced: 3 months ago
JSON representation

NestJS Casbin module with TypeORM Adapter

Awesome Lists containing this project

README

        


NestJs Casbin TypeORM




NestJS module for Casbin using the TypeORM Adapter



## Example

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

```typescript
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({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: async (configService: ConfigService) => ({
dbConnectionOptions: { // typeORM connectionOptions
type: 'mysql',
host: configService.get('MYSQL_HOST'),
port: configService.get('MYSQL_PORT'),
username: configService.get('MYSQL_USERNAME'),
password: configService.get('MYSQL_PASSWORD'),
database: configService.get('MYSQL_DATABASE'),
},
modelPath: "src/model/roles.conf"
}
)
],
controllers: [AppController],
providers: [AppService]
})
export class AppModule {}
```

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

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

## License

This project is [MIT licensed](LICENSE).