Skip to content

Commit

Permalink
test: reissue 테스트를 위한 로그 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
Mingyum-Kim committed Sep 12, 2023
1 parent 53e956a commit 40f9522
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/main/java/com/backend/auth/application/OAuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ public LoginResponse login(String provider, String uid, String fcmToken) {
String accessToken = tokenProvider.generateAccessToken(uid);
String refreshToken = tokenProvider.generateRefreshToken(uid);

log.info("save refresh token to redis : uid = {}, refresh token = {}", uid, refreshToken);
refreshTokenService.saveRefreshToken(uid, refreshToken);

boolean checkRefreshTokenSaved = refreshTokenService.checkRefreshTokenSaved(uid, refreshToken);
log.info("check uid and refresh token saved : {}" , checkRefreshTokenSaved);

fcmTokenService.saveFcmToken(uid, fcmToken);

return new LoginResponse(isFirstLogin, accessToken, refreshToken);
Expand All @@ -42,6 +47,7 @@ public ReissueResponse reissue(String bearerRefreshToken) throws Exception {
log.info("refresh token : " + refreshToken);
String uid = refreshTokenService.findUidByRefreshToken(refreshToken);

log.info("uid : " + uid);
String renewAccessToken = tokenProvider.generateAccessToken(uid);
String renewRefreshToken = tokenProvider.generateRefreshToken(uid);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Optional;

@Service
@RequiredArgsConstructor
public class RefreshTokenService {
Expand All @@ -23,6 +25,12 @@ public String findUidByRefreshToken(String refreshToken){
return result.getUid();
}

public boolean checkRefreshTokenSaved(String uid, String refreshToken){
Optional<RefreshToken> result = refreshTokenRepository.findByUidAndTokenValue(uid, refreshToken);
if(result.isPresent()) return true;
return false;
}

public void deleteByUid(String uid) {
refreshTokenRepository.findById(uid).orElseThrow(() -> new BusinessException(ErrorCode.MEMBER_NOT_FOUND));
refreshTokenRepository.deleteById(uid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@

public interface RefreshTokenRepository extends CrudRepository<RefreshToken, String> {
Optional<RefreshToken> findByTokenValue(String refreshToken);

Optional<RefreshToken> findByUidAndTokenValue(String uid, String refreshToken);
}

0 comments on commit 40f9522

Please sign in to comment.