Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pardjs/nest-casbin
Make magic with Nest.js, Casbin and TypeORM.
https://github.com/pardjs/nest-casbin
casbin nestjs typeorm typescript
Last synced: 3 months ago
JSON representation
Make magic with Nest.js, Casbin and TypeORM.
- Host: GitHub
- URL: https://github.com/pardjs/nest-casbin
- Owner: pardjs
- Created: 2019-02-21T07:46:54.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-03T16:34:38.000Z (about 2 years ago)
- Last Synced: 2024-09-29T01:42:42.110Z (3 months ago)
- Topics: casbin, nestjs, typeorm, typescript
- Language: TypeScript
- Homepage:
- Size: 516 KB
- Stars: 21
- Watchers: 3
- Forks: 4
- Open Issues: 19
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# nest-casbin
Make magic with [Nest.js](https://github.com/nestjs/nest), [Casbin](https://github.com/casbin/casbin) and [TypeORM](https://github.com/typeorm/typeorm).
## 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 { 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:
```typescript
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");
}
}
```