Skip to content

Conversation

@jjeonghak
Copy link
Collaborator

관련 이슈 번호

#26 #23 #30

작업 내용

  • jwt access & refresh token 전략 구현
  • 회원가입/로그인/로그아웃/토큰재발급 기능 구현

고민과 학습내용

로그인 관련 작업을 일단 간단하게 구현해보았습니다.
Authoriaztion 헤더와 X-Refresh-Toekn 헤더에 jwt 토큰을 이용해서 처리하는 방식입니다.

@jjeonghak jjeonghak added Feature 새로운 기능을 추가 BE 서버 작업 labels Nov 10, 2024
@jjeonghak jjeonghak self-assigned this Nov 10, 2024
@PMtHk
Copy link
Collaborator

PMtHk commented Nov 10, 2024

@jjeonghak
포매팅 관련해서 슬랙에 메시지 남겨두었습니다.
혹시, JSON 파일에도 포매팅이 적용되는 지, 확인부탁드립니다.

PMtHk
PMtHk previously approved these changes Nov 10, 2024
Copy link
Collaborator

@PMtHk PMtHk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수고하셨습니다.
뷰 작업도 힘을 좀 내야겠군요!

import { Account } from '../entity/account.entity';

@Injectable()
export class AccountService {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


AccountService 는 AccountRepository 의 Wrapper 클래스로 사용하신 건가요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아직 Account에 별다른 정보와 기능이 없어서 지금은 래퍼 클래스라고 봐도 무방한 것 같습니다. authService랑 분리를 일단 해두었는데 이후에도 별다른 기능이 없다면 사실 통합해도 될 것 같이요

iam454
iam454 previously approved these changes Nov 10, 2024
Copy link
Collaborator

@iam454 iam454 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

빠..빠르다..!
(끄응 솔직히 nest 코드 잘 모르겠습니다.. ㅠㅠ)

throw new UnauthorizedException('Invalid refresh token');
}
const accessToken = await this.generateAccessToken({ id: user.id, username: user.username });
return { accessToken, refreshToken };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

access 토큰 재발급 로직에서 refresh 토큰은 재발급 하지 않아도 괜찮을까요 ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

access 토큰은 재발급하고, refresh 토큰이 만료되면 다시 로그인해야하는 로직으로 구현했습니다

Comment on lines +65 to +77
private generateAccessToken(payload: { id: number; username: string }) {
return this.jwtService.signAsync(payload, {
secret: this.configService.get<string>('JWT_ACCESS_TOKEN_SECRET'),
expiresIn: this.configService.get<string>('JWT_ACCESS_TOKEN_TIME'),
});
}

private generateRefreshToken(payload: { id: number; username: string }) {
return this.jwtService.signAsync(payload, {
secret: this.configService.get<string>('JWT_REFRESH_TOKEN_SECRET'),
expiresIn: this.configService.get<string>('JWT_REFRESH_TOKEN_TIME'),
});
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

토큰 생성 로직은 별도 클래스로 분리하는 것도 괜찮을 것 같아요 !

yangchef1
yangchef1 previously approved these changes Nov 10, 2024
yangchef1
yangchef1 previously approved these changes Nov 11, 2024
@jjeonghak jjeonghak merged commit 89d2a5d into boostcampwm-2024:dev Nov 11, 2024
2 checks passed
@jjeonghak jjeonghak deleted the feat/#26 branch November 13, 2024 08:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

BE 서버 작업 Feature 새로운 기능을 추가

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants