Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Commit

Permalink
🔒 Add scopes and guards on user routes
Browse files Browse the repository at this point in the history
  • Loading branch information
AnandChowdhary committed Oct 23, 2020
1 parent 93d82e1 commit 653ccfc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ import { UsersModule } from './modules/user/user.module';
PrismaModule,
UsersModule,
AuthModule,
RateLimiterModule,
RateLimiterModule.register({
points: 100,
duration: 60,
}),
EmailModule,
],
controllers: [AppController],
Expand Down
6 changes: 6 additions & 0 deletions src/modules/user/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export class UserController {
constructor(private usersService: UsersService) {}

@Get()
@UseGuards(ScopesGuard)
@Scopes('user:read')
async getAll(
@Query('skip', OptionalIntPipe) skip?: number,
@Query('take', OptionalIntPipe) take?: number,
Expand All @@ -45,6 +47,8 @@ export class UserController {
}

@Patch(':id')
@UseGuards(ScopesGuard)
@Scopes('user{id}:write')
async update(
@Param('id', ParseIntPipe) id: number,
@Body() data: UpdateUserDto,
Expand All @@ -53,6 +57,8 @@ export class UserController {
}

@Delete(':id')
@UseGuards(ScopesGuard)
@Scopes('user{id}:delete')
async remove(@Param('id', ParseIntPipe) id: number): Promise<Expose<users>> {
return this.usersService.deleteUser({ id: Number(id) });
}
Expand Down

0 comments on commit 653ccfc

Please sign in to comment.