Skip to content

Commit

Permalink
Merge pull request #53 from Modagbul/fix/auth
Browse files Browse the repository at this point in the history
Fix/auth : 로그인 시 fcmToken 업데이트 되게 수정
  • Loading branch information
minsu20 authored Nov 4, 2023
2 parents bdc6c11 + 3bb711b commit d24cb5a
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
@NoArgsConstructor
@Getter
public class SignInRequest {
@NotBlank(message="token 을 입력해주세요.")
private String token;
@NotBlank(message="socialToken 을 입력해주세요.")
private String socialToken;

@NotBlank(message = "fcmToken 을 입력해주세요.")
private String fcmToken;

}

Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,4 @@ public class SignUpRequest {
@NotNull(message="birthDate 을 입력해주세요.")
@Pattern(regexp = "^\\d{4}-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])$", message = "날짜 형식이 잘못되었습니다. YYYY-MM-DD 형식으로 입력해주세요.")
private String birthDate;

@NotBlank(message = "fcmToken 을 입력해주세요.")
private String fcmToken;

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
public class TestRequest {
private String socialId;

private String fcmToken;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public class MemberAuthUserCase {
private final MemberSaveService memberSaveService;

@Transactional
public Member auth(Member member, String providerInfo) {
public Member auth(String fcmToken, Member member, String providerInfo) {
member.updateFcmToken(fcmToken);
Member signInMember = memberSaveService.saveMember(member);
checkRegistration(signInMember, providerInfo);
return signInMember;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.moing.backend.domain.auth.application.service;

import com.moing.backend.domain.auth.application.dto.request.SignInRequest;
import com.moing.backend.domain.auth.application.dto.response.SignInResponse;
import com.moing.backend.domain.member.domain.constant.RegistrationStatus;
import com.moing.backend.domain.member.domain.entity.Member;
Expand All @@ -23,11 +24,11 @@ public class SignInUserCase {
private final Map<String, SignInProvider> signInProviders;
private final MemberGetService memberGetService;

public SignInResponse signIn(String token, String providerInfo) {
public SignInResponse signIn(SignInRequest signInRequest, String providerInfo) {
//1. 사용자 정보 가져오기
Member member = getUserDataFromPlatform(token, providerInfo);
Member member = getUserDataFromPlatform(signInRequest.getSocialToken(), providerInfo);
//2. 로그인 및 회원가입
Member authenticatedMember = internalAuthService.auth(member, providerInfo);
Member authenticatedMember = internalAuthService.auth(signInRequest.getFcmToken(), member, providerInfo);
//3. security 처리
AuthenticationUtil.makeAuthentication(authenticatedMember);
//4. token 만들기
Expand All @@ -46,11 +47,11 @@ private Member getUserDataFromPlatform(String accessToken, String providerInfo)
return signInProvider.getUserData(accessToken);
}

public SignInResponse testSignIn(String socialId, String providerInfo) {
public SignInResponse testSignIn(String fcmToken, String socialId, String providerInfo) {
//1. 사용자 정보 가져오기
Member member = memberGetService.getMemberBySocialId(socialId);
//2. 로그인
Member authenticatedMember = internalAuthService.auth(member, providerInfo);
Member authenticatedMember = internalAuthService.auth(fcmToken, member, providerInfo);
//3. security 처리
AuthenticationUtil.makeAuthentication(authenticatedMember);
//4. token 만들기
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class AuthController {
@PostMapping("/signIn/{provider}")
public ResponseEntity<SuccessResponse<SignInResponse>> signIn(@PathVariable String provider,
@Valid @RequestBody SignInRequest signInRequest) {
return ResponseEntity.ok(SuccessResponse.create(SIGN_IN_SUCCESS.getMessage(), this.authService.signIn(signInRequest.getToken(), provider)));
return ResponseEntity.ok(SuccessResponse.create(SIGN_IN_SUCCESS.getMessage(), this.authService.signIn(signInRequest, provider)));
}

/**
Expand Down Expand Up @@ -90,6 +90,6 @@ public ResponseEntity<SuccessResponse<CheckNicknameResponse>> checkNickname(@Pat
@PostMapping("/test/{provider}")
public ResponseEntity<SuccessResponse<SignInResponse>> testLogin(@PathVariable String provider,
@RequestBody TestRequest testRequest){
return ResponseEntity.ok(SuccessResponse.create(SIGN_IN_SUCCESS.getMessage(), this.authService.testSignIn(testRequest.getSocialId(),provider)));
return ResponseEntity.ok(SuccessResponse.create(SIGN_IN_SUCCESS.getMessage(), this.authService.testSignIn(testRequest.getFcmToken(), testRequest.getSocialId(),provider)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,8 @@ public void signUp(SignUpRequest signUpRequest) {
this.nickName = signUpRequest.getNickName();
this.gender = signUpRequest.getGender();
this.birthDate = LocalDate.parse(signUpRequest.getBirthDate(), DateTimeFormatter.ISO_DATE);;
this.fcmToken = signUpRequest.getFcmToken();
this.registrationStatus = RegistrationStatus.COMPLETED;
this.isNewUploadPush=true;
this.isFirePush=true;
this.isRemindPush=true;
updateAllPush(true);
}

@Builder
Expand Down Expand Up @@ -145,6 +142,10 @@ public void updateAllPush(boolean allPush) {
this.isFirePush = allPush;
}

public void updateFcmToken(String fcmToken) {
this.fcmToken = fcmToken;
}

public Member(LocalDate birthDate, String email, String fcmToken, Gender gender, String introduction, String nickName, String profileImage, SocialProvider provider, RegistrationStatus registrationStatus, Role role, String socialId) {
this.birthDate = birthDate;
this.email = email;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public Member saveMember(Member member) {
if(findMember.isEmpty()){
return memberRepository.save(member);
} else {
findMember.get().updateFcmToken(member.getFcmToken());
return findMember.get();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ protected void configure(HttpSecurity http) throws Exception {
.antMatchers("/webjars/**").permitAll()
.antMatchers("/v3/api-docs").permitAll()
.antMatchers("/api/auth/**", "/docs/**", "/api/image/**").permitAll()
.antMatchers("/api/admin/**").hasRole("ADMIN")
.anyRequest().authenticated()
.and()
.apply(new JwtSecurityConfig(tokenUtil, memberQueryService));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ class AuthControllerTest extends CommonControllerTest {
public void Kakao_소셜_로그인_회원가입_전() throws Exception {
//given
SignInRequest input = SignInRequest.builder()
.token("KAKAO_ACCESS_TOKEN")
.fcmToken("FCM_TOKEN")
.socialToken("KAKAO_ACCESS_TOKEN")
.build();

String body = objectMapper.writeValueAsString(input);
Expand All @@ -74,7 +75,8 @@ class AuthControllerTest extends CommonControllerTest {
.andDo(
restDocs.document(
requestFields(
fieldWithPath("token").description("카카오 액세스 토큰")
fieldWithPath("fcmToken").description("FCM TOKEN"),
fieldWithPath("socialToken").description("카카오 액세스 토큰")
),
responseFields(
fieldWithPath("isSuccess").description("true"),
Expand All @@ -91,7 +93,8 @@ class AuthControllerTest extends CommonControllerTest {
public void Kakao_소셜_로그인_회원가입_후() throws Exception {
//given
SignInRequest input = SignInRequest.builder()
.token("KAKAO_ACCESS_TOKEN")
.fcmToken("FCM_TOKEN")
.socialToken("KAKAO_ACCESS_TOKEN")
.build();

String body = objectMapper.writeValueAsString(input);
Expand All @@ -117,7 +120,8 @@ class AuthControllerTest extends CommonControllerTest {
.andDo(
restDocs.document(
requestFields(
fieldWithPath("token").description("카카오 액세스 토큰")
fieldWithPath("fcmToken").description("FCM TOKEN"),
fieldWithPath("socialToken").description("카카오 액세스 토큰")
),
responseFields(
fieldWithPath("isSuccess").description("true"),
Expand All @@ -134,7 +138,8 @@ class AuthControllerTest extends CommonControllerTest {
public void Apple_소셜_로그인_회원가입_전() throws Exception {
//given
SignInRequest input = SignInRequest.builder()
.token("APPLE_IDENTITY_TOKEN")
.fcmToken("FCM_TOKEN")
.socialToken("APPLE_IDENTITY_TOKEN")
.build();

String body = objectMapper.writeValueAsString(input);
Expand All @@ -160,7 +165,8 @@ class AuthControllerTest extends CommonControllerTest {
.andDo(
restDocs.document(
requestFields(
fieldWithPath("token").description("애플 아이디 토큰")
fieldWithPath("fcmToken").description("FCM TOKEN"),
fieldWithPath("socialToken").description("애플 아이디 토큰")
),
responseFields(
fieldWithPath("isSuccess").description("true"),
Expand All @@ -177,7 +183,8 @@ class AuthControllerTest extends CommonControllerTest {
public void Apple_소셜_로그인_회원가입_후() throws Exception {
//given
SignInRequest input = SignInRequest.builder()
.token("APPLE_IDENTITY_TOKEN")
.fcmToken("FCM_TOKEN")
.socialToken("APPLE_IDENTITY_TOKEN")
.build();

String body = objectMapper.writeValueAsString(input);
Expand All @@ -203,7 +210,8 @@ class AuthControllerTest extends CommonControllerTest {
.andDo(
restDocs.document(
requestFields(
fieldWithPath("token").description("애플 아이디 토큰")
fieldWithPath("fcmToken").description("FCM TOKEN"),
fieldWithPath("socialToken").description("애플 아이디 토큰")
),
responseFields(
fieldWithPath("isSuccess").description("true"),
Expand All @@ -220,7 +228,8 @@ class AuthControllerTest extends CommonControllerTest {
public void GOOGLE_소셜_로그인_회원가입_전() throws Exception {
//given
SignInRequest input = SignInRequest.builder()
.token("APPLE_IDENTITY_TOKEN")
.fcmToken("FCM_TOKEN")
.socialToken("APPLE_IDENTITY_TOKEN")
.build();

String body = objectMapper.writeValueAsString(input);
Expand All @@ -246,7 +255,8 @@ class AuthControllerTest extends CommonControllerTest {
.andDo(
restDocs.document(
requestFields(
fieldWithPath("token").description("구글 아이디 토큰")
fieldWithPath("fcmToken").description("FCM TOKEN"),
fieldWithPath("socialToken").description("애플 아이디 토큰")
),
responseFields(
fieldWithPath("isSuccess").description("true"),
Expand All @@ -263,7 +273,8 @@ class AuthControllerTest extends CommonControllerTest {
public void GOOGLE_소셜_로그인_회원가입_후() throws Exception {
//given
SignInRequest input = SignInRequest.builder()
.token("APPLE_IDENTITY_TOKEN")
.fcmToken("FCM_TOKEN")
.socialToken("APPLE_IDENTITY_TOKEN")
.build();

String body = objectMapper.writeValueAsString(input);
Expand All @@ -289,7 +300,8 @@ class AuthControllerTest extends CommonControllerTest {
.andDo(
restDocs.document(
requestFields(
fieldWithPath("token").description("구글 아이디 토큰")
fieldWithPath("fcmToken").description("FCM TOKEN"),
fieldWithPath("socialToken").description("애플 아이디 토큰")
),
responseFields(
fieldWithPath("isSuccess").description("true"),
Expand All @@ -310,7 +322,6 @@ public void sign_up() throws Exception {
.nickName("NICKNAME")
.gender(Gender.MAN)
.birthDate("2000-03-28")
.fcmToken("FCMTOKEN")
.build();

String body = objectMapper.writeValueAsString(input);
Expand Down Expand Up @@ -344,8 +355,7 @@ public void sign_up() throws Exception {
requestFields(
fieldWithPath("nickName").description("유저 닉네임"),
fieldWithPath("gender").description("성별"),
fieldWithPath("birthDate").description("태어난 날짜(YYYY-MM-DD)"),
fieldWithPath("fcmToken").description("FCM TOKEN")
fieldWithPath("birthDate").description("태어난 날짜(YYYY-MM-DD)")
),
responseFields(
fieldWithPath("isSuccess").description("true"),
Expand Down

0 comments on commit d24cb5a

Please sign in to comment.