diff --git a/src/main/java/com/MeetMate/user/UserController.java b/src/main/java/com/MeetMate/user/UserController.java index 465939d..0eb8b82 100644 --- a/src/main/java/com/MeetMate/user/UserController.java +++ b/src/main/java/com/MeetMate/user/UserController.java @@ -148,6 +148,9 @@ public ResponseEntity deleteUser(@RequestHeader(name = "Authorization") Strin if (tc == EntityNotFoundException.class) return ResponseEntity.status(HttpStatus.NOT_FOUND).body("message: " + t.getMessage()); + if (tc == IllegalAccessException.class) + return ResponseEntity.status(HttpStatus.FORBIDDEN).body("message: " + t.getMessage()); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) .body("type: " + tc + "\nmessage: " + t.getMessage()); } diff --git a/src/main/java/com/MeetMate/user/UserService.java b/src/main/java/com/MeetMate/user/UserService.java index fdedc10..2eda4b5 100644 --- a/src/main/java/com/MeetMate/user/UserService.java +++ b/src/main/java/com/MeetMate/user/UserService.java @@ -160,11 +160,14 @@ public RefreshResponse refreshAccessToken(String refreshToken) { } @Transactional - public void deleteUser(String token) { + public void deleteUser(String token) throws IllegalAccessException { String email = jwtService.extractUserEmail(token); User user = userRepository .findUserByEmail(email) .orElseThrow(() -> new EntityNotFoundException("User does not exist.")); + if (user.getRole() == UserRole.COMPANY_OWNER + || user.getRole() == UserRole.COMPANY_MEMBER) + throw new IllegalAccessException("Company owners and members cannot delete their accounts"); userRepository.deleteByEmail(email); }