diff --git a/src/auth/decorators/has-roles.decorator.ts b/src/auth/decorators/roles.decorator.ts similarity index 61% rename from src/auth/decorators/has-roles.decorator.ts rename to src/auth/decorators/roles.decorator.ts index 3fedb2c..63374d9 100644 --- a/src/auth/decorators/has-roles.decorator.ts +++ b/src/auth/decorators/roles.decorator.ts @@ -2,4 +2,4 @@ import { SetMetadata } from '@nestjs/common' import { Role } from '../guards/role.enum' export const ROLES_KEY = 'roles' -export const HasRoles = (...roles: Role[]) => SetMetadata(ROLES_KEY, roles) +export const Roles = (...roles: Role[]) => SetMetadata(ROLES_KEY, roles) diff --git a/src/auth/guards/roles.guard.ts b/src/auth/guards/roles.guard.ts index ceee602..2119c12 100644 --- a/src/auth/guards/roles.guard.ts +++ b/src/auth/guards/roles.guard.ts @@ -1,7 +1,7 @@ import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common' import { Reflector } from '@nestjs/core' import { Observable } from 'rxjs' -import { ROLES_KEY } from '../decorators/has-roles.decorator' +import { ROLES_KEY } from '../decorators/roles.decorator' import { Role } from './role.enum' //참고: https://shpota.com/2022/07/16/role-based-authorization-with-jwt-using-nestjs.html diff --git a/src/user/user.controller.ts b/src/user/user.controller.ts index ab0f78c..5dd32c1 100644 --- a/src/user/user.controller.ts +++ b/src/user/user.controller.ts @@ -13,7 +13,7 @@ import { import { User } from '@prisma/client' import { UserDTO } from './dtos/user.dto' import { UserService } from './user.service' -import { HasRoles } from '../auth/decorators/has-roles.decorator' +import { Roles } from '../auth/decorators/roles.decorator' import { JwtAuthGuard } from '../auth/guards/jwt.authguard' import { Role } from '../auth/guards/role.enum' import { RolesGuard } from '../auth/guards/roles.guard' @@ -127,14 +127,14 @@ export class UserController { return result } - @HasRoles(Role.USER) + @Roles(Role.USER) @UseGuards(JwtAuthGuard, RolesGuard) @Get(':id') - async fetchOne(@Param('id') id: number): Promise { + async fetchOne(@Param('id') id: string): Promise { return await this.userService.fetchOne({ id: Number(id) }) } - // @HasRoles(Role.USER) + // @Roles(Role.USER) // @UseGuards(JwtAuthGuard, RolesGuard) //@UseGuards(JwtAuthGuard) @Post() @@ -142,7 +142,7 @@ export class UserController { return await this.userService.add(data) } - @HasRoles(Role.USER) + @Roles(Role.USER) @UseGuards(JwtAuthGuard, RolesGuard) @Put(':id') async update(@Param('id') id: string, @Body() data: UserDTO): Promise { @@ -153,7 +153,7 @@ export class UserController { }) } - @HasRoles(Role.USER) + @Roles(Role.USER) @UseGuards(JwtAuthGuard, RolesGuard) @Delete(':id') async delete(@Param('id') id: string): Promise {