Skip to content

Commit

Permalink
Merge pull request #26 from Team-baebae/feature/kakao/#25
Browse files Browse the repository at this point in the history
Feat: 카카오 토큰 기반 기존 회원 유무 판별 API 추가
  • Loading branch information
tioon authored May 2, 2024
2 parents 8e7c8e9 + dfa8252 commit 1547a90
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ public MemberResponse.SignUpResponse login(HttpServletRequest httpServletRequest
}
}

public MemberResponse.isExistingUserResponse checkIsExisting(HttpServletRequest httpServletRequest){
//카카오 토큰으로 정보 가져옴
KakaoUserInfoDto kakaoUserInfo = loginService.getKakaoUserInfo(httpServletRequest);

//이미 회원이 존재하면 true, 아니면 false
if(loginService.isExistingUser(kakaoUserInfo.getKakaoAccount().getEmail()))
return new MemberResponse.isExistingUserResponse(true);
else
return new MemberResponse.isExistingUserResponse(false);
}


public MemberResponse.AccessTokenResponse newAccessToken(String refreshToken) {
return manageTokenService.issueNewAccessToken(refreshToken); // 함수 호출
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public OpenAPI publicApi() {
.bearerFormat("JWT")
.scheme("Bearer");

Components components = new Components().addSecuritySchemes("token", securityScheme);
Components components = new Components().addSecuritySchemes("bearerAuth", securityScheme);

return new OpenAPI()
.info(info)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public final class SecurityConstants {

public static final String[] NO_AUTH_LIST = {
// oAuth2 인증 제외
"/api/oauth/kakao", "/favicon.ico", "/oauth/kakao/callback", "/api/oauth/login",
"/api/oauth/kakao", "/favicon.ico", "/oauth/kakao/callback", "/api/oauth/login", "/api/oauth/isExisting",
// Swagger 제외 과정
"/v3/**", "/swagger-ui/**",
// Error 페이지
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ public interface MemberRepository extends JpaRepository<Member, Long> {
boolean existsByEmail(String email);

Optional<Member> findByRefreshToken(String refreshToken);

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ public ResponseEntity<MemberResponse.SignUpResponse> oauthSignUp(
return ResponseEntity.ok(memberApplication.login(httpServletRequest, signUpRequest));
}

//회원가입 유무 판별
@GetMapping("/isExisting")
public ResponseEntity<MemberResponse.isExistingUserResponse> isExistingUser(
HttpServletRequest httpServletRequest
) {
return ResponseEntity.ok(memberApplication.checkIsExisting(httpServletRequest));
}


// Access Token 재발급
@PostMapping("/token/refresh")
Expand Down Expand Up @@ -64,4 +72,8 @@ public ResponseEntity<Void> logout(HttpServletRequest httpServletRequest) {

return ResponseEntity.ok().build();
}




}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,33 @@ ResponseEntity< MemberResponse.SignUpResponse> oauthSignUp(
HttpServletRequest httpServletRequest
);

@Operation(
summary = "회원가입 유무 체크",
security = @SecurityRequirement(name = "bearerAuth")
)
@Parameter(
in = ParameterIn.HEADER,
name = "Authorization", required = true,
schema = @Schema(type = "string"),
description = "Bearer [카카오 Access 토큰]")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "기존 회원",
content = @Content(mediaType = "application/json",
examples = @ExampleObject(value = "{\n" +
" \"isExisting\": \"true\"\n" +
"}"))
),
@ApiResponse(responseCode = "200", description = "새로운 회원",
content = @Content(mediaType = "application/json",
examples = @ExampleObject(value = "{\n" +
" \"isExisting\": \"false\"\n" +
"}"))
)
})
public ResponseEntity<MemberResponse.isExistingUserResponse> isExistingUser(
HttpServletRequest httpServletRequest
);



@Operation(summary = "Access Token 재발급")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,12 @@ public static AccessTokenResponse of(Member member, String accessToken) {

}


@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public static class isExistingUserResponse {
private Boolean isExisting;
}
}

0 comments on commit 1547a90

Please sign in to comment.