diff --git a/src/main/java/cotato/growingpain/auth/controller/AuthController.java b/src/main/java/cotato/growingpain/auth/controller/AuthController.java index 2254124..6796b7c 100644 --- a/src/main/java/cotato/growingpain/auth/controller/AuthController.java +++ b/src/main/java/cotato/growingpain/auth/controller/AuthController.java @@ -11,6 +11,7 @@ import cotato.growingpain.security.jwt.Token; import cotato.growingpain.security.jwt.dto.request.ReissueRequest; import cotato.growingpain.security.jwt.dto.response.ReissueResponse; +import cotato.growingpain.security.oauth.AuthProvider; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Schema; @@ -44,7 +45,7 @@ public class AuthController { @ResponseStatus(HttpStatus.OK ) public Response joinAuth(@RequestBody @Valid LoginRequest request) { log.info("[일반 로그인 컨트롤러]: {}", request.email()); - return Response.createSuccess("회원가입 및 로그인 완료", authService.createLoginInfo(request)); + return Response.createSuccess("회원가입 및 로그인 완료", authService.createLoginInfo(AuthProvider.GENERAL, request)); } @Operation(summary = "추가 정보 입력", description = "최초 로그인 (회원가입) 시 추가 정보를 입력하는 메소드") diff --git a/src/main/java/cotato/growingpain/auth/service/AuthService.java b/src/main/java/cotato/growingpain/auth/service/AuthService.java index a661144..c7f8133 100644 --- a/src/main/java/cotato/growingpain/auth/service/AuthService.java +++ b/src/main/java/cotato/growingpain/auth/service/AuthService.java @@ -42,7 +42,7 @@ public class AuthService { private final BlackListRepository blackListRepository; @Transactional - public Token createLoginInfo(LoginRequest request) { + public Token createLoginInfo(AuthProvider authProvider, LoginRequest request) { Optional existingMember = memberRepository.findByEmail(request.email()); @@ -72,13 +72,7 @@ public Token createLoginInfo(LoginRequest request) { log.info("[회원 가입 서비스]: {}", request.email()); - Member member = Member.builder() - .password(bCryptPasswordEncoder.encode(request.password())) - .email(request.email()) - .memberRole(MemberRole.PENDING) - .authProvider(AuthProvider.GENERAL) - .build(); - memberRepository.save(member); + Member member = registerMember(authProvider, request.email(), request.password()); // 회원가입 성공 후 토큰 생성 및 반환 Token token = jwtTokenProvider.createToken(member.getId(), member.getEmail(), MemberRole.PENDING.getDescription()); @@ -89,6 +83,19 @@ public Token createLoginInfo(LoginRequest request) { } } + private Member registerMember(AuthProvider authProvider, String email, String password) { + Member.MemberBuilder memberBuilder = Member.builder() + .email(email) + .authProvider(authProvider) + .memberRole(MemberRole.PENDING); + + if (authProvider == AuthProvider.GENERAL) { + memberBuilder.password(bCryptPasswordEncoder.encode(password)); + } + + return memberRepository.save(memberBuilder.build()); + } + @Transactional public Token completeSignup(CompleteSignupRequest request, String accessToken) {