diff --git a/src/main/java/com/haemil/backend/auth/controller/AuthController.java b/src/main/java/com/haemil/backend/auth/controller/AuthController.java index 759dba5..803374a 100644 --- a/src/main/java/com/haemil/backend/auth/controller/AuthController.java +++ b/src/main/java/com/haemil/backend/auth/controller/AuthController.java @@ -31,9 +31,10 @@ public class AuthController { private long CookiePeriod; @PostMapping("/kakao") - public ResponseEntity loginKakao(@RequestBody KakaoLoginParams params) { + public ResponseEntity loginKakao(@RequestParam Boolean isGuardian, @RequestBody KakaoLoginParams params) { try { - RespLoginDto respLoginDto = authService.login(params); + log.debug("isGuardian = {}", isGuardian); + RespLoginDto respLoginDto = authService.login(params, isGuardian); HttpHeaders headers = respLoginDto.getHeaders(); LoginDto loginDto = respLoginDto.getLoginDto(); diff --git a/src/main/java/com/haemil/backend/auth/service/AuthService.java b/src/main/java/com/haemil/backend/auth/service/AuthService.java index 2a12837..8afcfea 100644 --- a/src/main/java/com/haemil/backend/auth/service/AuthService.java +++ b/src/main/java/com/haemil/backend/auth/service/AuthService.java @@ -45,10 +45,10 @@ public class AuthService { private long CookiePeriod; // 로그인: 인증 정보 저장 및 비어 토큰 발급 - public RespLoginDto login(OAuthLoginParams params) throws BaseException { + public RespLoginDto login(OAuthLoginParams params, Boolean isGuardian) throws BaseException { OAuthInfoResponse oAuthInfoResponse = requestOAuthInfoService.request(params); - Long userId = findOrCreateUser(oAuthInfoResponse); + Long userId = findOrCreateUser(oAuthInfoResponse, isGuardian); AuthTokens token = createToken(userId, oAuthInfoResponse); User user = userRepository.findById(userId).orElseThrow(() -> new BaseException(ResponseStatus.NO_USER)); @@ -218,19 +218,20 @@ public ResponseCookie saveHttpCookie(AuthTokens token) { return httpCookie; } - private Long findOrCreateUser(OAuthInfoResponse oAuthInfoResponse) { + private Long findOrCreateUser(OAuthInfoResponse oAuthInfoResponse, Boolean isGuardian) { return userRepository.findByEmail(oAuthInfoResponse.getEmail()) .map(User::getId) - .orElseGet(() -> newUser(oAuthInfoResponse)); + .orElseGet(() -> newUser(oAuthInfoResponse, isGuardian)); } - private Long newUser(OAuthInfoResponse oAuthInfoResponse) { + private Long newUser(OAuthInfoResponse oAuthInfoResponse, Boolean isGuardian) { User user = User.builder() .email(oAuthInfoResponse.getEmail()) .nickname(oAuthInfoResponse.getNickname()) .profileImageUrl(oAuthInfoResponse.getProfileImageUrl()) .oAuthProvider(oAuthInfoResponse.getOAuthProvider()) .role(User.Role.USER) // 추가. + .guardian(isGuardian) .build(); return userRepository.save(user).getId(); diff --git a/src/main/java/com/haemil/backend/user/entity/User.java b/src/main/java/com/haemil/backend/user/entity/User.java index c7b3573..c441377 100644 --- a/src/main/java/com/haemil/backend/user/entity/User.java +++ b/src/main/java/com/haemil/backend/user/entity/User.java @@ -37,28 +37,30 @@ public class User { // 프로필 이미지 url 추가. @Column private String profileImageUrl; - private OAuthProvider oAuthProvider; @Getter @RequiredArgsConstructor public enum Role { USER("ROLE_USER"), ADMIN("ROLE_ADMIN"); - private final String key; } + // 보호자 여부 + public Boolean guardian; + // public enum OAuthProvider { // KAKAO, GOOGLE // } @Builder - public User(String email, String nickname, String profileImageUrl, Role role, OAuthProvider oAuthProvider) { + public User(String email, String nickname, String profileImageUrl, Role role, OAuthProvider oAuthProvider, Boolean guardian) { this.email = email; this.nickname = nickname; this.profileImageUrl = profileImageUrl; this.role = role; this.oAuthProvider = oAuthProvider; + this.guardian = guardian; } public User update(String name, String picture){