From fcbdf3550038ced2b8fc9052720e45595a39f7f7 Mon Sep 17 00:00:00 2001 From: koomin1227 Date: Mon, 8 Apr 2024 21:52:14 +0900 Subject: [PATCH 01/11] =?UTF-8?q?Deps:=20@nestjs/passport=20passport-jwt?= =?UTF-8?q?=20@types/passport-jwt=20=EC=84=A4=EC=B9=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 81 ++++++++++++++++++++++++++++++++++++++++++++++- package.json | 5 ++- 2 files changed, 84 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index f81518c..696fea2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,16 +14,19 @@ "@nestjs/config": "^3.2.0", "@nestjs/core": "^10.0.0", "@nestjs/jwt": "^10.2.0", + "@nestjs/passport": "^10.0.3", "@nestjs/platform-express": "^10.0.0", "@nestjs/typeorm": "^10.0.2", + "@types/passport-jwt": "^4.0.1", "axios": "^1.6.8", "class-transformer": "^0.5.1", "class-validator": "^0.14.1", + "jest-fetch-mock": "^3.0.3", "jsonwebtoken": "^9.0.2", "jwks-rsa": "^3.1.0", - "jest-fetch-mock": "^3.0.3", "mysql2": "^3.9.2", "nest-winston": "^1.9.4", + "passport-jwt": "^4.0.1", "reflect-metadata": "^0.2.0", "rxjs": "^7.8.1", "typeorm": "^0.3.20", @@ -1861,6 +1864,15 @@ "@types/node": "*" } }, + "node_modules/@nestjs/passport": { + "version": "10.0.3", + "resolved": "https://registry.npmjs.org/@nestjs/passport/-/passport-10.0.3.tgz", + "integrity": "sha512-znJ9Y4S8ZDVY+j4doWAJ8EuuVO7SkQN3yOBmzxbGaXbvcSwFDAdGJ+OMCg52NdzIO4tQoN4pYKx8W6M0ArfFRQ==", + "peerDependencies": { + "@nestjs/common": "^8.0.0 || ^9.0.0 || ^10.0.0", + "passport": "^0.4.0 || ^0.5.0 || ^0.6.0 || ^0.7.0" + } + }, "node_modules/@nestjs/platform-express": { "version": "10.3.5", "resolved": "https://registry.npmjs.org/@nestjs/platform-express/-/platform-express-10.3.5.tgz", @@ -2264,6 +2276,32 @@ "undici-types": "~5.26.4" } }, + "node_modules/@types/passport": { + "version": "1.0.16", + "resolved": "https://registry.npmjs.org/@types/passport/-/passport-1.0.16.tgz", + "integrity": "sha512-FD0qD5hbPWQzaM0wHUnJ/T0BBCJBxCeemtnCwc/ThhTg3x9jfrAcRUmj5Dopza+MfFS9acTe3wk7rcVnRIp/0A==", + "dependencies": { + "@types/express": "*" + } + }, + "node_modules/@types/passport-jwt": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/@types/passport-jwt/-/passport-jwt-4.0.1.tgz", + "integrity": "sha512-Y0Ykz6nWP4jpxgEUYq8NoVZeCQPo1ZndJLfapI249g1jHChvRfZRO/LS3tqu26YgAS/laI1qx98sYGz0IalRXQ==", + "dependencies": { + "@types/jsonwebtoken": "*", + "@types/passport-strategy": "*" + } + }, + "node_modules/@types/passport-strategy": { + "version": "0.2.38", + "resolved": "https://registry.npmjs.org/@types/passport-strategy/-/passport-strategy-0.2.38.tgz", + "integrity": "sha512-GC6eMqqojOooq993Tmnmp7AUTbbQSgilyvpCYQjT+H6JfG/g6RGc7nXEniZlp0zyKJ0WUdOiZWLBZft9Yug1uA==", + "dependencies": { + "@types/express": "*", + "@types/passport": "*" + } + }, "node_modules/@types/qs": { "version": "6.9.14", "resolved": "https://registry.npmjs.org/@types/qs/-/qs-6.9.14.tgz", @@ -7314,6 +7352,41 @@ "node": ">= 0.8" } }, + "node_modules/passport": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/passport/-/passport-0.7.0.tgz", + "integrity": "sha512-cPLl+qZpSc+ireUvt+IzqbED1cHHkDoVYMo30jbJIdOOjQ1MQYZBPiNvmi8UM6lJuOpTPXJGZQk0DtC4y61MYQ==", + "peer": true, + "dependencies": { + "passport-strategy": "1.x.x", + "pause": "0.0.1", + "utils-merge": "^1.0.1" + }, + "engines": { + "node": ">= 0.4.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/jaredhanson" + } + }, + "node_modules/passport-jwt": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/passport-jwt/-/passport-jwt-4.0.1.tgz", + "integrity": "sha512-UCKMDYhNuGOBE9/9Ycuoyh7vP6jpeTp/+sfMJl7nLff/t6dps+iaeE0hhNkKN8/HZHcJ7lCdOyDxHdDoxoSvdQ==", + "dependencies": { + "jsonwebtoken": "^9.0.0", + "passport-strategy": "^1.0.0" + } + }, + "node_modules/passport-strategy": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/passport-strategy/-/passport-strategy-1.0.0.tgz", + "integrity": "sha512-CB97UUvDKJde2V0KDWWB3lyf6PC3FaZP7YxZ2G8OAtn9p4HI9j9JLP9qjOGZFvyl8uwNT8qM+hGnz/n16NI7oA==", + "engines": { + "node": ">= 0.4.0" + } + }, "node_modules/path-exists": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", @@ -7383,6 +7456,12 @@ "node": ">=8" } }, + "node_modules/pause": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/pause/-/pause-0.0.1.tgz", + "integrity": "sha512-KG8UEiEVkR3wGEb4m5yZkVCzigAD+cVEJck2CzYZO37ZGJfctvVptVO192MwrtPhzONn6go8ylnOdMhKqi4nfg==", + "peer": true + }, "node_modules/picocolors": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz", diff --git a/package.json b/package.json index ed27d62..6a927c9 100644 --- a/package.json +++ b/package.json @@ -25,16 +25,19 @@ "@nestjs/config": "^3.2.0", "@nestjs/core": "^10.0.0", "@nestjs/jwt": "^10.2.0", + "@nestjs/passport": "^10.0.3", "@nestjs/platform-express": "^10.0.0", "@nestjs/typeorm": "^10.0.2", + "@types/passport-jwt": "^4.0.1", "axios": "^1.6.8", "class-transformer": "^0.5.1", "class-validator": "^0.14.1", + "jest-fetch-mock": "^3.0.3", "jsonwebtoken": "^9.0.2", "jwks-rsa": "^3.1.0", - "jest-fetch-mock": "^3.0.3", "mysql2": "^3.9.2", "nest-winston": "^1.9.4", + "passport-jwt": "^4.0.1", "reflect-metadata": "^0.2.0", "rxjs": "^7.8.1", "typeorm": "^0.3.20", From 33214aab2bdb1d132b50477a2684fa10f789d402 Mon Sep 17 00:00:00 2001 From: koomin1227 Date: Mon, 8 Apr 2024 21:52:47 +0900 Subject: [PATCH 02/11] =?UTF-8?q?Feat:=20JwtStrategy=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/auth/auth.module.ts | 3 ++- src/auth/jwt.strategy.ts | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 src/auth/jwt.strategy.ts diff --git a/src/auth/auth.module.ts b/src/auth/auth.module.ts index cfab57e..10e0829 100644 --- a/src/auth/auth.module.ts +++ b/src/auth/auth.module.ts @@ -4,10 +4,11 @@ import { AuthService } from './auth.service'; import { JwtConfig } from '../Config/jwt.config'; import { JwtModule } from '@nestjs/jwt'; import { UserModule } from '../user/user.module'; +import { JwtStrategy } from './jwt.strategy'; @Module({ imports: [JwtModule.registerAsync({ useClass: JwtConfig }), UserModule], controllers: [AuthController], - providers: [AuthService], + providers: [AuthService, JwtStrategy], }) export class AuthModule {} diff --git a/src/auth/jwt.strategy.ts b/src/auth/jwt.strategy.ts new file mode 100644 index 0000000..d075103 --- /dev/null +++ b/src/auth/jwt.strategy.ts @@ -0,0 +1,19 @@ +import { Injectable } from '@nestjs/common'; +import { PassportStrategy } from '@nestjs/passport'; +import { ExtractJwt, Strategy } from 'passport-jwt'; +import { ConfigService } from '@nestjs/config'; + +@Injectable() +export class JwtStrategy extends PassportStrategy(Strategy) { + constructor(private configService: ConfigService) { + super({ + jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(), + ignoreExpiration: false, + secretOrKey: configService.get('JWT_SECRET'), + }); + } + + async validate(payload: any) { + return { userId: payload.sub }; + } +} From 64adea54c9753781915d60ab944f3ff8df6a7d6e Mon Sep 17 00:00:00 2001 From: koomin1227 Date: Mon, 8 Apr 2024 22:02:17 +0900 Subject: [PATCH 03/11] =?UTF-8?q?Feat:=20JwtAuthGuard=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/auth/jwt-auth.guard.ts | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 src/auth/jwt-auth.guard.ts diff --git a/src/auth/jwt-auth.guard.ts b/src/auth/jwt-auth.guard.ts new file mode 100644 index 0000000..2155290 --- /dev/null +++ b/src/auth/jwt-auth.guard.ts @@ -0,0 +1,5 @@ +import { Injectable } from '@nestjs/common'; +import { AuthGuard } from '@nestjs/passport'; + +@Injectable() +export class JwtAuthGuard extends AuthGuard('jwt') {} From 7e7046146cfb548a5767d2a1b9d5347f164d2475 Mon Sep 17 00:00:00 2001 From: koomin1227 Date: Mon, 8 Apr 2024 23:59:24 +0900 Subject: [PATCH 04/11] =?UTF-8?q?Feat:=20userId=20=ED=9A=8D=EB=93=9D=20?= =?UTF-8?q?=EB=B0=A9=EB=B2=95=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/auth/jwt.strategy.ts | 2 +- src/decorator/user-id.decorator.ts | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 src/decorator/user-id.decorator.ts diff --git a/src/auth/jwt.strategy.ts b/src/auth/jwt.strategy.ts index d075103..cf5bffe 100644 --- a/src/auth/jwt.strategy.ts +++ b/src/auth/jwt.strategy.ts @@ -14,6 +14,6 @@ export class JwtStrategy extends PassportStrategy(Strategy) { } async validate(payload: any) { - return { userId: payload.sub }; + return { userId: payload.userId }; } } diff --git a/src/decorator/user-id.decorator.ts b/src/decorator/user-id.decorator.ts new file mode 100644 index 0000000..246a3c8 --- /dev/null +++ b/src/decorator/user-id.decorator.ts @@ -0,0 +1,9 @@ +import { createParamDecorator, ExecutionContext } from '@nestjs/common'; + +export const UserId = createParamDecorator( + (data: unknown, ctx: ExecutionContext) => { + // Guard 이후에 실행되므로 jwtToken의 유효성은 보장 + const request = ctx.switchToHttp().getRequest(); + return request.user.userId; + }, +); From e94f17f947a27d4c0e9adfd0e22721b76bc8e323 Mon Sep 17 00:00:00 2001 From: koomin1227 Date: Tue, 9 Apr 2024 00:14:33 +0900 Subject: [PATCH 05/11] =?UTF-8?q?Feat:=20algorithmController=20=EC=97=90?= =?UTF-8?q?=20=EA=B0=80=EB=93=9C=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/algorithm/algorithm.controller.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/algorithm/algorithm.controller.ts b/src/algorithm/algorithm.controller.ts index 5514f0e..4829cc0 100644 --- a/src/algorithm/algorithm.controller.ts +++ b/src/algorithm/algorithm.controller.ts @@ -1,14 +1,24 @@ -import { Body, Controller, Delete, Param, Patch, Post } from '@nestjs/common'; +import { + Body, + Controller, + Delete, + Param, + Patch, + Post, + UseGuards, +} from '@nestjs/common'; import { AlgorithmService } from './algorithm.service'; import { CreateAlgorithmDto } from './createAlgorithm.dto'; +import { JwtAuthGuard } from '../auth/jwt-auth.guard'; +import { UserId } from '../decorator/user-id.decorator'; +@UseGuards(JwtAuthGuard) @Controller('api/stat/algorithm') export class AlgorithmController { constructor(private readonly algorithmService: AlgorithmService) {} @Post() - async algorithmCreate(@Body() body: CreateAlgorithmDto) { - const userId = 'user'; + async algorithmCreate(@Body() body: CreateAlgorithmDto, @UserId() userId) { await this.algorithmService.createAlgorithm(userId, body.bojId); } From ea566f1c6429613a2fb933feea2f36b9512a7deb Mon Sep 17 00:00:00 2001 From: koomin1227 Date: Tue, 9 Apr 2024 00:15:04 +0900 Subject: [PATCH 06/11] =?UTF-8?q?Feat:=20githubController=20=EC=97=90=20?= =?UTF-8?q?=EA=B0=80=EB=93=9C=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/github/github.controller.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/github/github.controller.ts b/src/github/github.controller.ts index d914418..c85f215 100644 --- a/src/github/github.controller.ts +++ b/src/github/github.controller.ts @@ -2,22 +2,23 @@ import { Body, Controller, Delete, - Get, Param, Patch, Post, - Query, + UseGuards, } from '@nestjs/common'; import { GithubService } from './github.service'; import { CreateGithubDto } from './createGitub.dto'; +import { JwtAuthGuard } from '../auth/jwt-auth.guard'; +import { UserId } from '../decorator/user-id.decorator'; +@UseGuards(JwtAuthGuard) @Controller('api/stat/github') export class GithubController { constructor(private readonly githubService: GithubService) {} @Post() - public async gitHubCreate(@Body() body: CreateGithubDto) { - const userId = '123'; + public async gitHubCreate(@Body() body: CreateGithubDto, @UserId() userId) { await this.githubService.createGithub(body, userId); } From 5e8fdc2663a3c758c02a24a13b8ee506be46349b Mon Sep 17 00:00:00 2001 From: koomin1227 Date: Tue, 9 Apr 2024 00:41:10 +0900 Subject: [PATCH 07/11] =?UTF-8?q?Feat:=20OwnershipGuard=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84=20-=20=EB=B3=B8=EC=9D=B8=EC=9D=98=20=EC=9E=90?= =?UTF-8?q?=EC=9B=90=EB=A7=8C=20=EC=88=98=EC=A0=95=ED=95=98=EA=B2=8C=20?= =?UTF-8?q?=EB=A7=89=EC=9D=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/auth/ownership.guard.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/auth/ownership.guard.ts diff --git a/src/auth/ownership.guard.ts b/src/auth/ownership.guard.ts new file mode 100644 index 0000000..6542fba --- /dev/null +++ b/src/auth/ownership.guard.ts @@ -0,0 +1,21 @@ +import { + CanActivate, + ExecutionContext, + ForbiddenException, + Injectable, +} from '@nestjs/common'; +import { AuthGuard } from '@nestjs/passport'; + +@Injectable() +export class OwnershipGuard implements CanActivate { + canActivate(context: ExecutionContext) { + const request = context.switchToHttp().getRequest(); + const requestedUserId = request.params.id; + const userId = request.user.userId; + if (requestedUserId !== userId) { + throw new ForbiddenException('삭제할 권한이 없습니다.'); + } + + return true; + } +} From ed78fe63c959531e876b98938f864112aacca36f Mon Sep 17 00:00:00 2001 From: koomin1227 Date: Tue, 9 Apr 2024 00:41:49 +0900 Subject: [PATCH 08/11] =?UTF-8?q?Feat:=20=EB=B3=B8=EC=9D=B8=EC=9D=98=20?= =?UTF-8?q?=EC=95=8C=EA=B3=A0=EB=A6=AC=EC=A6=98=20=EC=A0=95=EB=B3=B4?= =?UTF-8?q?=EB=A7=8C=20=EC=88=98=EC=A0=95=ED=95=98=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/algorithm/algorithm.controller.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/algorithm/algorithm.controller.ts b/src/algorithm/algorithm.controller.ts index 4829cc0..eecc6f5 100644 --- a/src/algorithm/algorithm.controller.ts +++ b/src/algorithm/algorithm.controller.ts @@ -11,6 +11,7 @@ import { AlgorithmService } from './algorithm.service'; import { CreateAlgorithmDto } from './createAlgorithm.dto'; import { JwtAuthGuard } from '../auth/jwt-auth.guard'; import { UserId } from '../decorator/user-id.decorator'; +import { OwnershipGuard } from '../auth/ownership.guard'; @UseGuards(JwtAuthGuard) @Controller('api/stat/algorithm') @@ -22,6 +23,7 @@ export class AlgorithmController { await this.algorithmService.createAlgorithm(userId, body.bojId); } + @UseGuards(OwnershipGuard) @Patch(':id') async algorithmModify( @Param('id') userId, @@ -30,6 +32,7 @@ export class AlgorithmController { await this.algorithmService.modifyAlgorithm(userId, body.bojId); } + @UseGuards(OwnershipGuard) @Delete(':id') async algorithmRemove(@Param('id') userId) { await this.algorithmService.removeAlgorithm(userId); From d286154a36c98af8fab1f0344dc08fd468ec41ca Mon Sep 17 00:00:00 2001 From: koomin1227 Date: Tue, 9 Apr 2024 00:42:29 +0900 Subject: [PATCH 09/11] =?UTF-8?q?Feat:=20=EB=B3=B8=EC=9D=B8=EC=9D=98=20?= =?UTF-8?q?=EA=B9=83=ED=97=88=EB=B8=8C=20=EC=A0=95=EB=B3=B4=EB=A7=8C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=ED=95=98=EB=8F=84=EB=A1=9D=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/github/github.controller.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/github/github.controller.ts b/src/github/github.controller.ts index c85f215..d95c2e9 100644 --- a/src/github/github.controller.ts +++ b/src/github/github.controller.ts @@ -11,6 +11,7 @@ import { GithubService } from './github.service'; import { CreateGithubDto } from './createGitub.dto'; import { JwtAuthGuard } from '../auth/jwt-auth.guard'; import { UserId } from '../decorator/user-id.decorator'; +import { OwnershipGuard } from '../auth/ownership.guard'; @UseGuards(JwtAuthGuard) @Controller('api/stat/github') @@ -22,6 +23,7 @@ export class GithubController { await this.githubService.createGithub(body, userId); } + @UseGuards(OwnershipGuard) @Patch(':id') public async gitHubModify( @Param('id') userId: string, @@ -30,6 +32,7 @@ export class GithubController { await this.githubService.modifyGithub(body, userId); } + @UseGuards(OwnershipGuard) @Delete(':id') public async gitHubDelete(@Param('id') userId: string) { await this.githubService.deleteGithub(userId); From 1482e101812337c362fcf559a2163be950ed9638 Mon Sep 17 00:00:00 2001 From: koomin1227 Date: Tue, 9 Apr 2024 00:45:27 +0900 Subject: [PATCH 10/11] =?UTF-8?q?Chore:=20=ED=8F=B4=EB=8D=94=EC=9D=B4?= =?UTF-8?q?=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/algorithm/algorithm.controller.ts | 4 ++-- src/auth/auth.module.ts | 2 +- src/auth/{ => guard}/jwt-auth.guard.ts | 0 src/auth/{ => guard}/ownership.guard.ts | 0 src/auth/{ => strategy}/jwt.strategy.ts | 0 src/github/github.controller.ts | 4 ++-- 6 files changed, 5 insertions(+), 5 deletions(-) rename src/auth/{ => guard}/jwt-auth.guard.ts (100%) rename src/auth/{ => guard}/ownership.guard.ts (100%) rename src/auth/{ => strategy}/jwt.strategy.ts (100%) diff --git a/src/algorithm/algorithm.controller.ts b/src/algorithm/algorithm.controller.ts index eecc6f5..f3b1086 100644 --- a/src/algorithm/algorithm.controller.ts +++ b/src/algorithm/algorithm.controller.ts @@ -9,9 +9,9 @@ import { } from '@nestjs/common'; import { AlgorithmService } from './algorithm.service'; import { CreateAlgorithmDto } from './createAlgorithm.dto'; -import { JwtAuthGuard } from '../auth/jwt-auth.guard'; +import { JwtAuthGuard } from '../auth/guard/jwt-auth.guard'; import { UserId } from '../decorator/user-id.decorator'; -import { OwnershipGuard } from '../auth/ownership.guard'; +import { OwnershipGuard } from '../auth/guard/ownership.guard'; @UseGuards(JwtAuthGuard) @Controller('api/stat/algorithm') diff --git a/src/auth/auth.module.ts b/src/auth/auth.module.ts index 10e0829..cdc000b 100644 --- a/src/auth/auth.module.ts +++ b/src/auth/auth.module.ts @@ -4,7 +4,7 @@ import { AuthService } from './auth.service'; import { JwtConfig } from '../Config/jwt.config'; import { JwtModule } from '@nestjs/jwt'; import { UserModule } from '../user/user.module'; -import { JwtStrategy } from './jwt.strategy'; +import { JwtStrategy } from './strategy/jwt.strategy'; @Module({ imports: [JwtModule.registerAsync({ useClass: JwtConfig }), UserModule], diff --git a/src/auth/jwt-auth.guard.ts b/src/auth/guard/jwt-auth.guard.ts similarity index 100% rename from src/auth/jwt-auth.guard.ts rename to src/auth/guard/jwt-auth.guard.ts diff --git a/src/auth/ownership.guard.ts b/src/auth/guard/ownership.guard.ts similarity index 100% rename from src/auth/ownership.guard.ts rename to src/auth/guard/ownership.guard.ts diff --git a/src/auth/jwt.strategy.ts b/src/auth/strategy/jwt.strategy.ts similarity index 100% rename from src/auth/jwt.strategy.ts rename to src/auth/strategy/jwt.strategy.ts diff --git a/src/github/github.controller.ts b/src/github/github.controller.ts index d95c2e9..f7341a4 100644 --- a/src/github/github.controller.ts +++ b/src/github/github.controller.ts @@ -9,9 +9,9 @@ import { } from '@nestjs/common'; import { GithubService } from './github.service'; import { CreateGithubDto } from './createGitub.dto'; -import { JwtAuthGuard } from '../auth/jwt-auth.guard'; +import { JwtAuthGuard } from '../auth/guard/jwt-auth.guard'; import { UserId } from '../decorator/user-id.decorator'; -import { OwnershipGuard } from '../auth/ownership.guard'; +import { OwnershipGuard } from '../auth/guard/ownership.guard'; @UseGuards(JwtAuthGuard) @Controller('api/stat/github') From 07aa78ed2a98445a1c337a05336db68bdeb9d2da Mon Sep 17 00:00:00 2001 From: koomin1227 Date: Tue, 9 Apr 2024 00:50:06 +0900 Subject: [PATCH 11/11] =?UTF-8?q?Refactor:=20=EA=B6=8C=ED=95=9C=20?= =?UTF-8?q?=EC=97=86=EC=9D=84=EC=8B=9C=20=EC=98=A4=EB=A5=98=20=EB=A9=94?= =?UTF-8?q?=EC=8B=9C=EC=A7=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/auth/guard/ownership.guard.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/auth/guard/ownership.guard.ts b/src/auth/guard/ownership.guard.ts index 6542fba..0b97982 100644 --- a/src/auth/guard/ownership.guard.ts +++ b/src/auth/guard/ownership.guard.ts @@ -4,7 +4,6 @@ import { ForbiddenException, Injectable, } from '@nestjs/common'; -import { AuthGuard } from '@nestjs/passport'; @Injectable() export class OwnershipGuard implements CanActivate { @@ -13,7 +12,7 @@ export class OwnershipGuard implements CanActivate { const requestedUserId = request.params.id; const userId = request.user.userId; if (requestedUserId !== userId) { - throw new ForbiddenException('삭제할 권한이 없습니다.'); + throw new ForbiddenException('수정할 권한이 없습니다.'); } return true;