Skip to content

Commit

Permalink
[FEAT] 회원 탈퇴 시 토큰 삭제 로직 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
EunbeenDev committed Aug 21, 2024
1 parent 68e72ce commit 41cea19
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package com.noplanb.domain.auth.repository;

import com.noplanb.domain.auth.domain.Token;
import com.noplanb.domain.user.domain.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.Optional;

@Repository
public interface TokenRepository extends JpaRepository<Token, Long> {
Optional<Token> findByEmail(String email);
Token findByEmail(String email);
Optional<Token> findByRefreshToken(String refreshToken);

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.noplanb.domain.user.application;

import com.noplanb.domain.auth.domain.Token;
import com.noplanb.domain.auth.repository.TokenRepository;
import com.noplanb.domain.character.domain.Character;
import com.noplanb.domain.character.repository.CharacterRepository;
import com.noplanb.domain.user.domain.User;
Expand All @@ -21,7 +23,8 @@
@Transactional(readOnly = true)
public class UserService {

final UserRepository userRepository;
private final TokenRepository tokenRepository;
private final UserRepository userRepository;
private final CharacterRepository characterRepository;

@Transactional
Expand Down Expand Up @@ -64,8 +67,16 @@ public ResponseEntity<?> getUserCharacterExist(UserPrincipal userPrincipal) {
@Transactional
public ResponseEntity<?> cancelAccount(UserPrincipal userPrincipal) {
User user = userRepository.findById(userPrincipal.getId()).orElseThrow(() -> new IllegalArgumentException("사용자를 찾을 수 없습니다."));
String email = user.getEmail();

// 토큰 정보 삭제
Token token = tokenRepository.findByEmail(email);
if (token != null) { tokenRepository.delete(token); }

// 캐릭터 정보 삭제
characterRepository.deleteByUser(user);

// 유저 정보 삭제
userRepository.delete(user);

ApiResponse apiResponse = ApiResponse.builder()
Expand Down

0 comments on commit 41cea19

Please sign in to comment.