Skip to content

Commit

Permalink
fix: Jwt 필터에서 회원가입 시 TokenException 발생 오류 해결 (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyeong-hyeok committed Aug 3, 2023
1 parent 2f999d7 commit c709dc4
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,16 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
String refreshToken = jwtService.extractRefreshToken(request)
.filter(jwtService::isTokenValid)
.orElse(null);
String email = jwtService.extractEmail(refreshToken).orElseThrow(() -> new TokenException(ErrorCode.INVALID_TOKEN));

// 리프레시 토큰이 요청 헤더에 존재하고 유효하다면, AccessToken이 만료된 것 -> AccessToken 재발급
if (refreshToken != null && isRefreshTokenMatch(email, refreshToken)) {
String newAccessToken = jwtService.createAccessToken(email);
String newRefreshToken = jwtService.createRefreshToken(email);
jwtService.updateRefreshToken(email, newRefreshToken);
jwtService.sendAccessAndRefreshToken(response, newAccessToken, refreshToken);
if (refreshToken != null) {
String email = jwtService.extractEmail(refreshToken).orElseThrow(() -> new TokenException(ErrorCode.INVALID_TOKEN));
if (isRefreshTokenMatch(email, refreshToken)) {
String newAccessToken = jwtService.createAccessToken(email);
String newRefreshToken = jwtService.createRefreshToken(email);
jwtService.updateRefreshToken(email, newRefreshToken);
jwtService.sendAccessAndRefreshToken(response, newAccessToken, refreshToken);
}
return;
}

Expand Down Expand Up @@ -97,6 +99,7 @@ public void checkAccessTokenAndAuthentication(HttpServletRequest request, HttpSe
* 파라미터의 유저 : 우리가 만든 회원 객체 / 빌더의 유저 : UserDetails의 User 객체
*/
public void saveAuthentication(Member member) {
log.info("saveAuthentication() 호출");
String password = member.getPassword();
if (password == null) { // 소셜 로그인 유저의 비밀번호 임의로 설정 하여 소셜 로그인 유저도 인증 되도록 설정
password = PasswordUtil.generateRandomPassword();
Expand Down

0 comments on commit c709dc4

Please sign in to comment.