Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REFACTOR] refresh token 쿠키로 처리 #139

Merged
merged 3 commits into from
Aug 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()));
}
}
Loading