diff --git a/backend/src/main/java/com/twtw/backend/domain/member/controller/AuthController.java b/backend/src/main/java/com/twtw/backend/domain/member/controller/AuthController.java index e951bdc2..8127580f 100644 --- a/backend/src/main/java/com/twtw/backend/domain/member/controller/AuthController.java +++ b/backend/src/main/java/com/twtw/backend/domain/member/controller/AuthController.java @@ -3,6 +3,7 @@ import com.twtw.backend.domain.member.dto.request.MemberSaveRequest; import com.twtw.backend.domain.member.dto.request.OAuthRequest; import com.twtw.backend.domain.member.dto.request.TokenRequest; +import com.twtw.backend.domain.member.dto.response.AfterLoginDto; import com.twtw.backend.domain.member.dto.response.TokenDto; import com.twtw.backend.domain.member.service.AuthService; @@ -34,13 +35,7 @@ public ResponseEntity saveMember(@RequestBody MemberSaveRequest member } @PostMapping("/login") - public ResponseEntity afterSocialLogin(@RequestBody OAuthRequest request) { - TokenDto tokenDto = authService.getTokenByOAuth(request); - - if (tokenDto == null) { - return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(tokenDto); - } else { - return ResponseEntity.status(HttpStatus.OK).body(tokenDto); - } + public ResponseEntity afterSocialLogin(@RequestBody OAuthRequest request) { + return ResponseEntity.status(HttpStatus.OK).body(authService.getTokenByOAuth(request)); } } diff --git a/backend/src/main/java/com/twtw/backend/domain/member/dto/response/AfterLoginDto.java b/backend/src/main/java/com/twtw/backend/domain/member/dto/response/AfterLoginDto.java new file mode 100644 index 00000000..3283358b --- /dev/null +++ b/backend/src/main/java/com/twtw/backend/domain/member/dto/response/AfterLoginDto.java @@ -0,0 +1,14 @@ +package com.twtw.backend.domain.member.dto.response; + +import com.twtw.backend.domain.member.entity.AuthStatus; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor +@AllArgsConstructor +public class AfterLoginDto { + private AuthStatus status; + private TokenDto tokenDto; +} diff --git a/backend/src/main/java/com/twtw/backend/domain/member/entity/AuthStatus.java b/backend/src/main/java/com/twtw/backend/domain/member/entity/AuthStatus.java new file mode 100644 index 00000000..c115defa --- /dev/null +++ b/backend/src/main/java/com/twtw/backend/domain/member/entity/AuthStatus.java @@ -0,0 +1,6 @@ +package com.twtw.backend.domain.member.entity; + +public enum AuthStatus { + SU, + SI +} diff --git a/backend/src/main/java/com/twtw/backend/domain/member/entity/Member.java b/backend/src/main/java/com/twtw/backend/domain/member/entity/Member.java index ed99daa8..ec365d2b 100644 --- a/backend/src/main/java/com/twtw/backend/domain/member/entity/Member.java +++ b/backend/src/main/java/com/twtw/backend/domain/member/entity/Member.java @@ -21,17 +21,14 @@ public class Member { private String profileImage; - private String phoneNumber; - @Enumerated(EnumType.STRING) private Role role; @Embedded private OAuth2Info oAuth2Info; - public Member(String nickname, String profileImage, String phoneNumber, Role role) { + public Member(String nickname, String profileImage, Role role) { this.nickname = nickname; this.profileImage = profileImage; - this.phoneNumber = phoneNumber; this.role = role; } diff --git a/backend/src/main/java/com/twtw/backend/domain/member/mapper/MemberMapper.java b/backend/src/main/java/com/twtw/backend/domain/member/mapper/MemberMapper.java index e0b7b1a0..3f726f8d 100644 --- a/backend/src/main/java/com/twtw/backend/domain/member/mapper/MemberMapper.java +++ b/backend/src/main/java/com/twtw/backend/domain/member/mapper/MemberMapper.java @@ -15,7 +15,6 @@ public Member toMemberEntity(MemberSaveRequest request) { new Member( request.getNickname(), request.getProfileImage(), - request.getPhoneNumber(), request.getRole()); return member; } diff --git a/backend/src/main/java/com/twtw/backend/domain/member/service/AuthService.java b/backend/src/main/java/com/twtw/backend/domain/member/service/AuthService.java index 9a9b33d2..933091a4 100644 --- a/backend/src/main/java/com/twtw/backend/domain/member/service/AuthService.java +++ b/backend/src/main/java/com/twtw/backend/domain/member/service/AuthService.java @@ -3,7 +3,9 @@ import com.twtw.backend.config.security.jwt.TokenProvider; import com.twtw.backend.domain.member.dto.request.MemberSaveRequest; import com.twtw.backend.domain.member.dto.request.OAuthRequest; +import com.twtw.backend.domain.member.dto.response.AfterLoginDto; import com.twtw.backend.domain.member.dto.response.TokenDto; +import com.twtw.backend.domain.member.entity.AuthStatus; import com.twtw.backend.domain.member.entity.Member; import com.twtw.backend.domain.member.entity.RefreshToken; import com.twtw.backend.domain.member.mapper.MemberMapper; @@ -64,7 +66,7 @@ public TokenDto saveMember(MemberSaveRequest request) { * 2.JWT 토큰 발급 -> OAuth 정보 (clientId , AuthType)으로 진행 * * */ - public TokenDto getTokenByOAuth(OAuthRequest request) { + public AfterLoginDto getTokenByOAuth(OAuthRequest request) { String clientId = request.getToken(); Optional member = @@ -74,10 +76,10 @@ public TokenDto getTokenByOAuth(OAuthRequest request) { Member curMember = member.get(); UsernamePasswordAuthenticationToken credit = tokenProvider.makeCredit(curMember); TokenDto tokenDto = saveRefreshToken(credit, curMember.getId().toString()); - return tokenDto; + return new AfterLoginDto(AuthStatus.SI,tokenDto); } - return null; + return new AfterLoginDto(AuthStatus.SU,null); } /* diff --git a/backend/src/test/java/com/twtw/backend/domain/member/controller/AuthControllerTest.java b/backend/src/test/java/com/twtw/backend/domain/member/controller/AuthControllerTest.java index 0b12fe08..322dd53d 100644 --- a/backend/src/test/java/com/twtw/backend/domain/member/controller/AuthControllerTest.java +++ b/backend/src/test/java/com/twtw/backend/domain/member/controller/AuthControllerTest.java @@ -14,7 +14,9 @@ import com.twtw.backend.domain.member.dto.request.MemberSaveRequest; import com.twtw.backend.domain.member.dto.request.OAuthRequest; import com.twtw.backend.domain.member.dto.request.TokenRequest; +import com.twtw.backend.domain.member.dto.response.AfterLoginDto; import com.twtw.backend.domain.member.dto.response.TokenDto; +import com.twtw.backend.domain.member.entity.AuthStatus; import com.twtw.backend.domain.member.entity.AuthType; import com.twtw.backend.domain.member.entity.Role; import com.twtw.backend.domain.member.service.AuthService; @@ -96,7 +98,7 @@ void saveMember() throws Exception { @DisplayName("멤버가 저장된 상태에서의 로그인 API가 수행되는가") void afterSocialLogin() throws Exception { // given - final TokenDto expected = new TokenDto("access.token.value", "refresh.token.value"); + final AfterLoginDto expected = new AfterLoginDto(AuthStatus.SI,new TokenDto("access.token.value", "refresh.token.value")); given(authService.getTokenByOAuth(any())).willReturn(expected); // when