Skip to content

Commit

Permalink
Merge pull request #139 from Team-Tiki/chore/#137-refresh-token
Browse files Browse the repository at this point in the history
[REFACTOR] refresh token 쿠키로 처리
  • Loading branch information
paragon0107 authored Aug 3, 2024
2 parents 8b056fc + 018b70b commit 4839645
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 63 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package com.tiki.server.auth.controller;

import com.tiki.server.auth.dto.request.LoginRequest;
import com.tiki.server.auth.dto.response.ReissueGetResponse;
import com.tiki.server.common.dto.SuccessResponse;
Expand Down Expand Up @@ -38,8 +39,10 @@ public ResponseEntity<SuccessResponse<SignInResultGetResponse>> signIn(
}

@GetMapping("/reissue")
public ResponseEntity<SuccessResponse<ReissueGetResponse>> reissue(HttpServletRequest httpServletRequest) {
val response = authService.reissueToken(httpServletRequest);
public ResponseEntity<SuccessResponse<ReissueGetResponse>> reissue(
@CookieValue(name = "refreshToken") String refreshToken
) {
val response = authService.reissueToken(refreshToken);
return ResponseEntity.created(UriGenerator.getUri("/"))
.body(SuccessResponse.success(SUCCESS_REISSUE_ACCESS_TOKEN.getMessage(), response));
}
Expand Down
9 changes: 3 additions & 6 deletions src/main/java/com/tiki/server/auth/service/AuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import com.tiki.server.member.adapter.MemberFinder;
import com.tiki.server.member.entity.Member;
import com.tiki.server.member.exception.MemberException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.Authentication;
Expand Down Expand Up @@ -54,9 +53,7 @@ public SignInGetResponse login(LoginRequest request, HttpServletResponse respons
return SignInGetResponse.from(accessToken, refreshToken);
}

public ReissueGetResponse reissueToken(HttpServletRequest request) {
System.out.println("1");
val refreshToken = jwtProvider.getTokenFromRequest(request);
public ReissueGetResponse reissueToken(String refreshToken) {
checkTokenEmpty(refreshToken);
val memberId = jwtProvider.getUserFromJwt(refreshToken);
val token = tokenFinder.findById(memberId);
Expand All @@ -70,8 +67,8 @@ private Member checkMemberEmpty(LoginRequest request) {
return memberFinder.findByEmail(request.email()).orElseThrow(() -> new MemberException(INVALID_MEMBER));
}

private void checkTokenEmpty(String token){
if(StringUtils.isEmpty(token)){
private void checkTokenEmpty(String token) {
if (StringUtils.isEmpty(token)) {
throw new AuthException(EMPTY_JWT);
}
}
Expand Down
109 changes: 54 additions & 55 deletions src/main/java/com/tiki/server/common/handler/ErrorHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,67 +24,66 @@
@RestControllerAdvice
public class ErrorHandler {

@ExceptionHandler(MemberException.class)
public ResponseEntity<BaseResponse> memberException(MemberException exception) {
log.error(exception.getMessage());
val errorCode = exception.getErrorCode();
return ResponseEntity.status(errorCode.getHttpStatus()).body(ErrorResponse.of(errorCode.getMessage()));
}
@ExceptionHandler(MemberException.class)
public ResponseEntity<BaseResponse> memberException(MemberException exception) {
log.error(exception.getMessage());
val errorCode = exception.getErrorCode();
return ResponseEntity.status(errorCode.getHttpStatus()).body(ErrorResponse.of(errorCode.getMessage()));
}

@ExceptionHandler(TeamException.class)
public ResponseEntity<BaseResponse> teamException(TeamException exception) {
log.error(exception.getMessage());
val errorCode = exception.getErrorCode();
return ResponseEntity.status(errorCode.getHttpStatus()).body(ErrorResponse.of(errorCode.getMessage()));
}
@ExceptionHandler(TeamException.class)
public ResponseEntity<BaseResponse> teamException(TeamException exception) {
log.error(exception.getMessage());
val errorCode = exception.getErrorCode();
return ResponseEntity.status(errorCode.getHttpStatus()).body(ErrorResponse.of(errorCode.getMessage()));
}

@ExceptionHandler(MemberTeamManagerException.class)
public ResponseEntity<BaseResponse> memberTeamManagerException(MemberTeamManagerException exception) {
log.error(exception.getMessage());
val errorCode = exception.getErrorCode();
return ResponseEntity.status(errorCode.getHttpStatus()).body(ErrorResponse.of(errorCode.getMessage()));
}
@ExceptionHandler(MemberTeamManagerException.class)
public ResponseEntity<BaseResponse> memberTeamManagerException(MemberTeamManagerException exception) {
log.error(exception.getMessage());
val errorCode = exception.getErrorCode();
return ResponseEntity.status(errorCode.getHttpStatus()).body(ErrorResponse.of(errorCode.getMessage()));
}

@ExceptionHandler(TimeBlockException.class)
public ResponseEntity<BaseResponse> timeBlockException(TimeBlockException exception) {
log.error(exception.getMessage());
val errorCode = exception.getErrorCode();
return ResponseEntity.status(errorCode.getHttpStatus()).body(ErrorResponse.of(errorCode.getMessage()));
}
@ExceptionHandler(TimeBlockException.class)
public ResponseEntity<BaseResponse> timeBlockException(TimeBlockException exception) {
log.error(exception.getMessage());
val errorCode = exception.getErrorCode();
return ResponseEntity.status(errorCode.getHttpStatus()).body(ErrorResponse.of(errorCode.getMessage()));
}

@ExceptionHandler(DocumentException.class)
public ResponseEntity<BaseResponse> documentException(DocumentException exception) {
log.error(exception.getMessage());
val errorCode = exception.getErrorCode();
return ResponseEntity.status(errorCode.getHttpStatus()).body(ErrorResponse.of(errorCode.getMessage()));
}
@ExceptionHandler(DocumentException.class)
public ResponseEntity<BaseResponse> documentException(DocumentException exception) {
log.error(exception.getMessage());
val errorCode = exception.getErrorCode();
return ResponseEntity.status(errorCode.getHttpStatus()).body(ErrorResponse.of(errorCode.getMessage()));
}

@ExceptionHandler(ExternalException.class)
public ResponseEntity<BaseResponse> externalException(ExternalException exception) {
log.error(exception.getMessage());
val errorCode = exception.getErrorCode();
return ResponseEntity.status(errorCode.getHttpStatus()).body(ErrorResponse.of(errorCode.getMessage()));
}
@ExceptionHandler(ExternalException.class)
public ResponseEntity<BaseResponse> externalException(ExternalException exception) {
log.error(exception.getMessage());
val errorCode = exception.getErrorCode();
return ResponseEntity.status(errorCode.getHttpStatus()).body(ErrorResponse.of(errorCode.getMessage()));
}

@ExceptionHandler(MailException.class)
public ResponseEntity<BaseResponse> MailException(MailException exception) {
log.error(exception.getMessage());
val errorCode = exception.getErrorCode();
return ResponseEntity.status(errorCode.getHttpStatus()).body(ErrorResponse.of(errorCode.getMessage()));
}
@ExceptionHandler(MailException.class)
public ResponseEntity<BaseResponse> MailException(MailException exception) {
log.error(exception.getMessage());
val errorCode = exception.getErrorCode();
return ResponseEntity.status(errorCode.getHttpStatus()).body(ErrorResponse.of(errorCode.getMessage()));
}

@ExceptionHandler(AuthException.class)
public ResponseEntity<BaseResponse> AuthException(AuthException exception) {
log.error(exception.getMessage());
val errorCode = exception.getErrorCode();
return ResponseEntity.status(errorCode.getHttpStatus()).body(ErrorResponse.of(errorCode.getMessage()));
}
@ExceptionHandler(AuthException.class)
public ResponseEntity<BaseResponse> AuthException(AuthException exception) {
log.error(exception.getMessage());
val errorCode = exception.getErrorCode();
return ResponseEntity.status(errorCode.getHttpStatus()).body(ErrorResponse.of(errorCode.getMessage()));
}

@ExceptionHandler(Exception.class)
public ResponseEntity<BaseResponse> Exception(Exception exception) {
log.info("here!!");
log.error(exception.getMessage());
val errorCode = UNCAUGHT_SERVER_EXCEPTION;
return ResponseEntity.status(errorCode.getHttpStatus()).body(ErrorResponse.of(errorCode.getMessage()));
}
@ExceptionHandler(Exception.class)
public ResponseEntity<BaseResponse> Exception(Exception exception) {
log.error(exception.getMessage());
val errorCode = UNCAUGHT_SERVER_EXCEPTION;
return ResponseEntity.status(errorCode.getHttpStatus()).body(ErrorResponse.of(errorCode.getMessage()));
}
}

0 comments on commit 4839645

Please sign in to comment.