Skip to content

Commit

Permalink
refactor: 변수 네이밍 수정
Browse files Browse the repository at this point in the history
- `issueActiveInfoIdCookie(String)` -> `issueActiveInfoIdCookieByEmail(String)`
  • Loading branch information
soomanbaek committed Oct 21, 2023
1 parent 4e1cc68 commit b679453
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
22 changes: 11 additions & 11 deletions src/main/java/blacktokkies/toquiz/domain/member/api/AuthApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,53 +30,53 @@ ResponseEntity<SuccessMessage> signUp(@RequestBody @Valid SignUpRequest signUpRe

@PostMapping("/api/auth/login")
ResponseEntity<SuccessResponse<AuthenticateResponse>> login(@RequestBody @Valid LoginRequest loginRequest,
HttpServletResponse response) {
HttpServletResponse httpResponse) {
AuthenticateResponse loginResponse = authService.login(loginRequest);

response.addCookie(cookieService.issueActiveInfoIdCookie(loginResponse.getEmail()));
response.addCookie(cookieService.issueRefreshTokenCookie(loginResponse.getEmail()));
httpResponse.addCookie(cookieService.issueActiveInfoIdCookieByEmail(loginResponse.getEmail()));
httpResponse.addCookie(cookieService.issueRefreshTokenCookie(loginResponse.getEmail()));

return ResponseEntity.ok(new SuccessResponse<>(loginResponse));
}

@PostMapping("/api/auth/logout")
ResponseEntity<SuccessMessage> logout(
HttpServletResponse response,
HttpServletResponse httpResponse,
@AuthenticationPrincipal Member member
){
authService.logout(member);

// 로그아웃 시 서버에서 activeInfoId, refreshToken을 만료하고, 클라이언트에서 accessToken을 만료 함.
response.addCookie(cookieService.expireCookie("active_info_id"));
response.addCookie(cookieService.expireCookie("refresh_token"));
httpResponse.addCookie(cookieService.expireCookie("active_info_id"));
httpResponse.addCookie(cookieService.expireCookie("refresh_token"));

return ResponseEntity.ok(SuccessMessage.LOGOUT);
}

@PostMapping("api/auth/resign")
public ResponseEntity<SuccessMessage> deleteMyInfo(
@RequestBody @Valid ResignRequest request,
HttpServletResponse response,
HttpServletResponse httpResponse,
@AuthenticationPrincipal Member member,
@CookieValue("active_info_id") String activeInfoId
){
authService.resign(member, request.getPassword(), activeInfoId);

response.addCookie(cookieService.expireCookie("active_info_id"));
response.addCookie(cookieService.expireCookie("refresh_token"));
httpResponse.addCookie(cookieService.expireCookie("active_info_id"));
httpResponse.addCookie(cookieService.expireCookie("refresh_token"));

return ResponseEntity.ok(SuccessMessage.RESIGN);
}

@PostMapping ("/api/auth/refresh")
ResponseEntity<SuccessResponse<AuthenticateResponse>> refresh(
HttpServletResponse response,
HttpServletResponse httpResponse,
@AuthenticationPrincipal Member member,
@CookieValue(name = "refresh_token", required = false) String refreshToken
){
AuthenticateResponse refreshResponse = authService.refresh(member, refreshToken);

response.addCookie(cookieService.issueRefreshTokenCookie(refreshResponse.getEmail()));
httpResponse.addCookie(cookieService.issueRefreshTokenCookie(refreshResponse.getEmail()));

return ResponseEntity.ok(new SuccessResponse<>(refreshResponse));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class CookieService {
@Value("${application.security.cookie.refresh-token.expiration}")
private Integer REFRESH_TOKEN_EXPIRATION;

// 익명 사용자 ActiveInfoId 쿠키 발급
public Cookie issueActiveInfoIdCookie(){
ActiveInfo activeInfo = activeInfoRepository.save(new ActiveInfo());
Cookie cookie = new Cookie("active_info_id", activeInfo.getId());
Expand All @@ -33,7 +34,8 @@ public Cookie issueActiveInfoIdCookie(){
return cookie;
}

public Cookie issueActiveInfoIdCookie(String email){
// 로그인 사용자 ActiveInfoId 쿠키 발급
public Cookie issueActiveInfoIdCookieByEmail(String email){
Member member = memberRepository.findByEmail(email)
.orElseThrow(() -> new RestApiException(MemberErrorCode.NOT_EXIST_MEMBER));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ private ResultActions requestApi(LoginRequest request) throws Exception {

doReturn(response).when(authService).login(any(LoginRequest.class));
doReturn(refreshTokenCookie).when(cookieService).issueRefreshTokenCookie(any(String.class));
doReturn(activeInfoIdCookie).when(cookieService).issueActiveInfoIdCookie(any(String.class));
doReturn(activeInfoIdCookie).when(cookieService).issueActiveInfoIdCookieByEmail(any(String.class));

// when
final ResultActions resultActions = requestApi(request);
Expand Down

0 comments on commit b679453

Please sign in to comment.