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

[Feature/#235] 온보딩에서의 토큰 유효성 검사 API 작성 #236

Merged
merged 3 commits into from
Mar 31, 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
Expand Up @@ -15,6 +15,7 @@
import org.springframework.web.HttpMediaTypeNotSupportedException;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.MissingRequestHeaderException;
import org.springframework.web.bind.MissingServletRequestParameterException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
Expand Down Expand Up @@ -116,6 +117,14 @@ protected ResponseEntity<ApiResponse> UnknownHostException(final UnknownHostExce
.body(ApiResponse.error(Error.BAD_REQUEST_VALIDATION, Error.BAD_REQUEST_VALIDATION.getMessage()));
}

@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(MissingRequestHeaderException.class)
protected ResponseEntity<ApiResponse> MissingRequestHeaderException(final MissingRequestHeaderException e){
Sentry.captureException(e);
return ResponseEntity.status(Error.BAD_REQUEST_VALIDATION.getErrorCode())
.body(ApiResponse.error(Error.BAD_REQUEST_VALIDATION, Error.BAD_REQUEST_VALIDATION.getMessage()));
}



/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.app.toaster.config.UserId;
import com.app.toaster.controller.request.auth.SignInRequestDto;
import com.app.toaster.controller.response.auth.SignInResponseDto;
import com.app.toaster.controller.response.auth.TokenHealthDto;
import com.app.toaster.controller.response.auth.TokenResponseDto;
import com.app.toaster.exception.Success;
import com.app.toaster.service.auth.AuthService;
Expand Down Expand Up @@ -56,4 +57,10 @@ public ApiResponse withdraw(@UserId Long userId) {
authService.withdraw(userId);
return ApiResponse.success(Success.DELETE_USER_SUCCESS);
}

@PostMapping("/token/health")
@ResponseStatus(HttpStatus.OK)
public ApiResponse<TokenHealthDto> checkHealthOfToken(@RequestHeader String token) {
return ApiResponse.success(Success.TOKEN_HEALTH_CHECKED_SUCCESS, authService.checkHealthOfToken(token));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.app.toaster.controller.response.auth;

public record TokenHealthDto(boolean tokenHealth) {
public static TokenHealthDto of(boolean tokenHealth){return new TokenHealthDto(tokenHealth);}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public enum Success {

LOGIN_SUCCESS(HttpStatus.OK, "로그인 성공"),
RE_ISSUE_TOKEN_SUCCESS(HttpStatus.OK, "토큰 재발급 성공"),
TOKEN_HEALTH_CHECKED_SUCCESS(HttpStatus.OK, "토큰 헬스체크 성공"),
SIGNOUT_SUCCESS(HttpStatus.OK, "로그아웃 성공"),
DELETE_USER_SUCCESS(HttpStatus.OK, "회원 탈퇴가 정상적으로 이루어졌습니다."),
DELETE_TOAST_SUCCESS(HttpStatus.OK, "토스트 삭제 성공"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.RestTemplate;

import com.app.toaster.common.dto.ApiResponse;
import com.app.toaster.config.jwt.JwtService;
import com.app.toaster.controller.request.auth.SignInRequestDto;
import com.app.toaster.controller.response.auth.SignInResponseDto;
import com.app.toaster.controller.response.auth.TokenHealthDto;
import com.app.toaster.controller.response.auth.TokenResponseDto;
import com.app.toaster.domain.SocialType;
import com.app.toaster.domain.User;
Expand Down Expand Up @@ -156,4 +158,9 @@ public void withdraw(Long userId) {
}
}

@Transactional(readOnly = true)
public TokenHealthDto checkHealthOfToken(String refreshToken){
return TokenHealthDto.of(jwtService.verifyToken(refreshToken));
}

}
Loading