diff --git a/BE/src/auth/auth.controller.ts b/BE/src/auth/auth.controller.ts index 8fcdf300..02c5198c 100644 --- a/BE/src/auth/auth.controller.ts +++ b/BE/src/auth/auth.controller.ts @@ -47,7 +47,7 @@ export class AuthController { @Get('/test') @UseGuards(AuthGuard('jwt')) test(@Req() req: Request) { - return req; + return 'test'; } @ApiOperation({ summary: 'Kakao 로그인 API' }) diff --git a/BE/src/auth/strategy/jwt.strategy.ts b/BE/src/auth/strategy/jwt.strategy.ts index 7f8f5d2a..78063d1f 100644 --- a/BE/src/auth/strategy/jwt.strategy.ts +++ b/BE/src/auth/strategy/jwt.strategy.ts @@ -5,6 +5,7 @@ import { Injectable, UnauthorizedException } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; import { UserRepository } from '../user.repository'; import { User } from '../user.entity'; +import { Request } from 'express'; @Injectable() export class JwtStrategy extends PassportStrategy(Strategy) { @@ -14,7 +15,7 @@ export class JwtStrategy extends PassportStrategy(Strategy) { ) { super({ secretOrKey: configService.get('JWT_SECRET'), - jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(), + jwtFromRequest: extractJWTFromCookie, }); } @@ -31,3 +32,10 @@ export class JwtStrategy extends PassportStrategy(Strategy) { }; } } + +function extractJWTFromCookie(req: Request): string | null { + if (req.cookies && 'accessToken' in req.cookies) { + return req.cookies['accessToken']; + } + return null; +}