Skip to content

Commit

Permalink
refactor: refresh token 로직 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
zzangjyj0818 committed Aug 24, 2024
1 parent 6e04da8 commit a4d0399
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
import com.hackathon.ecocycle.global.oauth.exception.OAuthException;
import com.hackathon.ecocycle.global.oauth.service.RequestOAuthInfoService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


@Slf4j
@Service
@RequiredArgsConstructor
public class AuthService {
Expand Down Expand Up @@ -72,20 +74,20 @@ private Token createNewToken(Member member, TokenDto tokenDto) {

@Transactional
public TokenDto generateAccessToken(ReIssueRequestDto reIssueRequestDto) throws MemberNotFoundException, InvalidTokenException {
validateRefreshToken(reIssueRequestDto.getRefreshToken());

Token token = tokenRepository.findByRefreshToken(reIssueRequestDto.getRefreshToken());
Token token = validateRefreshToken(reIssueRequestDto);

Member member = memberRepository.findById(token.getMember().getMemberId())
.orElseThrow(() -> new MemberNotFoundException(ErrorCode.MEMBER_NOT_FOUND));

return createNewAccessToken(member, token.getRefreshToken());
}

private void validateRefreshToken(String refreshToken) throws InvalidTokenException {
if (tokenRepository.findByRefreshToken(refreshToken) == null || !jwtTokenProvider.validateToken(refreshToken)) {
private Token validateRefreshToken(ReIssueRequestDto reIssueRequestDto) throws InvalidTokenException {
Token token = tokenRepository.findByRefreshToken(reIssueRequestDto.getRefreshToken());
if (token.getRefreshToken() == null) {
throw new InvalidTokenException(ErrorCode.TOKEN_EXPIRED);
}
return token;
}

private TokenDto createNewAccessToken(Member member, String refreshToken) {
Expand Down

0 comments on commit a4d0399

Please sign in to comment.