Skip to content

Commit

Permalink
fix: invalidateTokenForCurrentMember메서드 추가 및 수정 (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbscks97 authored Aug 17, 2024
1 parent 5337054 commit a749bf8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@ public ResponseEntity<Void> storeToken(

@Operation(summary = "FCM 토큰 삭제", description = "로그아웃 시 FCM 토큰을 삭제합니다.")
@DeleteMapping("/token")
public ResponseEntity<Void> deleteToken(
@RequestBody @Validated FcmTokenRequest fcmTokenRequest) {
fcmTokenService.invalidateToken(fcmTokenRequest.token());
public ResponseEntity<Void> deleteToken() {
fcmTokenService.invalidateTokenForCurrentMember();
return ResponseEntity.ok().build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ private void handleBatchResponse(BatchResponse response, List<String> tokens) {
tokens.get(response.getResponses().indexOf(sendResponse));
if (isInvalidOrNotRegistered(sendResponse)) {
fcmTokenService.invalidateToken(token);
log.warn("FCM 토큰 {}이(가) 유효하지 않거나 등록되지 않았습니다. 토큰을 무효화합니다.", token);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ public List<String> getAllTokens() {
.toList();
}

@Transactional
public void invalidateTokenForCurrentMember() {
Member currentMember = memberUtil.getCurrentMember();
fcmRepository
.findByMember(currentMember)
.ifPresentOrElse(
fcmToken -> updateToken(fcmToken, ""),
() -> {
throw new CustomException(ErrorCode.FAILED_TO_FIND_FCM_TOKEN);
});
}

@Transactional
public void invalidateToken(String token) {
fcmRepository
Expand Down

0 comments on commit a749bf8

Please sign in to comment.