Skip to content

Commit

Permalink
🔧 fix : cookie를 이용한 accessToken validate(#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
jinddings committed Nov 19, 2024
1 parent a02a4fa commit 22dd87d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion BE/src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class AuthController {
@Get('/test')
@UseGuards(AuthGuard('jwt'))
test(@Req() req: Request) {

Check failure on line 49 in BE/src/auth/auth.controller.ts

View workflow job for this annotation

GitHub Actions / BE-test-and-build

'req' is defined but never used

Check failure on line 49 in BE/src/auth/auth.controller.ts

View workflow job for this annotation

GitHub Actions / build-and-deploy (be, BE, 3000, juga-docker-be)

'req' is defined but never used

Check failure on line 49 in BE/src/auth/auth.controller.ts

View workflow job for this annotation

GitHub Actions / build-and-deploy (be, BE, 3000, juga-docker-be)

'req' is defined but never used
return req;
return 'test';
}

@ApiOperation({ summary: 'Kakao 로그인 API' })
Expand Down
10 changes: 9 additions & 1 deletion BE/src/auth/strategy/jwt.strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -14,7 +15,7 @@ export class JwtStrategy extends PassportStrategy(Strategy) {
) {
super({
secretOrKey: configService.get<string>('JWT_SECRET'),
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
jwtFromRequest: extractJWTFromCookie,

Check failure on line 18 in BE/src/auth/strategy/jwt.strategy.ts

View workflow job for this annotation

GitHub Actions / BE-test-and-build

'extractJWTFromCookie' was used before it was defined

Check failure on line 18 in BE/src/auth/strategy/jwt.strategy.ts

View workflow job for this annotation

GitHub Actions / build-and-deploy (be, BE, 3000, juga-docker-be)

'extractJWTFromCookie' was used before it was defined

Check failure on line 18 in BE/src/auth/strategy/jwt.strategy.ts

View workflow job for this annotation

GitHub Actions / build-and-deploy (be, BE, 3000, juga-docker-be)

'extractJWTFromCookie' was used before it was defined
});
}

Expand All @@ -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'];

Check failure on line 38 in BE/src/auth/strategy/jwt.strategy.ts

View workflow job for this annotation

GitHub Actions / BE-test-and-build

Unsafe return of an `any` typed value

Check failure on line 38 in BE/src/auth/strategy/jwt.strategy.ts

View workflow job for this annotation

GitHub Actions / build-and-deploy (be, BE, 3000, juga-docker-be)

Unsafe return of an `any` typed value

Check failure on line 38 in BE/src/auth/strategy/jwt.strategy.ts

View workflow job for this annotation

GitHub Actions / build-and-deploy (be, BE, 3000, juga-docker-be)

Unsafe return of an `any` typed value
}
return null;
}

0 comments on commit 22dd87d

Please sign in to comment.