Skip to content

Commit

Permalink
refactor: nice 인증으로 진행하는 로그인 기능 개발 전 사용할 테스트용 로그인 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
eom-tae-in committed Sep 25, 2024
1 parent 3f143d7 commit 51da490
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.atwoz.alert.application.event.AlertTokenCreatedEvent;
import com.atwoz.global.event.Events;
import com.atwoz.member.application.auth.dto.LoginRequest;
import com.atwoz.member.application.auth.dto.TestLoginRequest;
import com.atwoz.member.domain.auth.MemberTokenProvider;
import com.atwoz.member.domain.member.Member;
import com.atwoz.member.domain.member.MemberRepository;
Expand All @@ -14,6 +15,7 @@

@RequiredArgsConstructor
@Service
@Transactional
public class MemberAuthService {

private static final String DEFAULT_PHONE_NUMBER = "01011111111";
Expand All @@ -25,7 +27,6 @@ public class MemberAuthService {
/**
* OAuth 인증방식과 PASS 인증 방식에 차이가 존재해서 회의 후 메서드 변경을 진행할 예정
*/
@Transactional
public String login(final LoginRequest request, final OAuthProviderRequest provider) {
String accessToken = oAuthRequester.getAccessToken(request.code(), provider);
MemberInfoResponse memberInfoResponse = oAuthRequester.getMemberInfo(accessToken, provider);
Expand All @@ -36,4 +37,12 @@ public String login(final LoginRequest request, final OAuthProviderRequest provi

return memberTokenProvider.createAccessToken(createdMember.getId());
}

//TODO: test를 위해 임시로 구현한 메서드입니다. 나중에 삭제해야합니다.
public String testLogin(final TestLoginRequest request) {
Member member = Member.createWithOAuth(request.phoneNumber());
memberRepository.save(member);

return memberTokenProvider.createAccessToken(member.getId());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.atwoz.member.application.auth.dto;

//TODO 잠깐 테스트 용도로 로그인을 허용하기 위해 만든 dto입니다. 나중에 삭제해야합니다.
public record TestLoginRequest(
String phoneNumber
) {
}
8 changes: 5 additions & 3 deletions src/main/java/com/atwoz/member/domain/member/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,11 @@ public static Member createWithPass(final String gender,
.build();
}

public void initializeWith(final String nickname,
final Long recommenderId,
final InternalProfileInitializeRequest internalProfileInitializeRequest) {
public void initializeWith(
final String nickname,
final Long recommenderId,
final InternalProfileInitializeRequest internalProfileInitializeRequest
) {
this.nickname = nickname;
initializeRecommenderId(recommenderId);
memberProfile.initialize(internalProfileInitializeRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.atwoz.member.application.auth.MemberAuthService;
import com.atwoz.member.application.auth.dto.LoginRequest;
import com.atwoz.member.application.auth.dto.TestLoginRequest;
import com.atwoz.member.infrastructure.auth.dto.OAuthProviderRequest;
import com.atwoz.member.ui.auth.dto.TokenResponse;
import com.atwoz.member.ui.auth.support.OAuthAuthority;
Expand All @@ -26,4 +27,10 @@ public ResponseEntity<TokenResponse> login(@RequestBody @Valid final LoginReques
String token = memberAuthService.login(request, provider);
return ResponseEntity.ok(new TokenResponse(token));
}

@PostMapping("/test-login")
public ResponseEntity<TokenResponse> testLogin(@RequestBody final TestLoginRequest request) {
String token = memberAuthService.testLogin(request);
return ResponseEntity.ok(new TokenResponse(token));
}
}

0 comments on commit 51da490

Please sign in to comment.