Skip to content

Commit

Permalink
[FIX] Login 수정 + Member 정보에서 전화번호 삭제 + AfterLoginDto 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
jinjoo-lab committed Sep 25, 2023
1 parent 9e053c1 commit 5c0ff04
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -34,13 +35,7 @@ public ResponseEntity<TokenDto> saveMember(@RequestBody MemberSaveRequest member
}

@PostMapping("/login")
public ResponseEntity<TokenDto> 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<AfterLoginDto> afterSocialLogin(@RequestBody OAuthRequest request) {
return ResponseEntity.status(HttpStatus.OK).body(authService.getTokenByOAuth(request));
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.twtw.backend.domain.member.entity;

public enum AuthStatus {
SU,
SI
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public Member toMemberEntity(MemberSaveRequest request) {
new Member(
request.getNickname(),
request.getProfileImage(),
request.getPhoneNumber(),
request.getRole());
return member;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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> member =
Expand All @@ -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);
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5c0ff04

Please sign in to comment.