Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/#14 social login kakao #15

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open

Conversation

GaHee99
Copy link
Contributor

@GaHee99 GaHee99 commented Jun 25, 2023

๐Ÿ–ผ๏ธ ์ž‘์—…ํ•œ ๋‚ด์šฉ

  • ์นด์นด์˜ค ์œ ์ € ์ฒดํฌ & ์ด๋ฏธ ํšŒ์›๊ฐ€์ž…ํ•œ ์‚ฌ์šฉ์ž์ธ์ง€ ์ฒดํฌํ•˜๋Š”
    [์นด์นด์˜ค ์ค‘๋ณต ์ฒดํฌ]๋ฅผ ๊ตฌํ˜„ํ–ˆ์Šต๋‹ˆ๋‹ค.

๐Ÿ“ธ PR Point

  • ๋กœ์ง flow๋ฅผ ๋…ธ๋“œ๋ž‘ ๋˜‘๊ฐ™์ด ํ•ด๋ดค์Šต๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‹ค๋ณด๋‹ˆ ์ปจํŠธ๋กค๋Ÿฌ์—์„œ data๋ฅผ ๋ฆฌํ„ดํ•˜๋Š”๋ถ€๋ถ„์ด, if-else๋กœ์ง์ด ๋“ค์–ด๊ฐ€์„œ ์ข€ ์ง€์ €๋ถ„ ํ•ด์ง€๋Š” ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.
    -> ์ด ๋ถ€๋ถ„์„ ์„œ๋น„์Šค ๋กœ์ง์œผ๋กœ ์˜ฎ๊ธฐ๋Š” ๊ฒƒ์€ ์–ด๋– ์‹ค๋ จ์ง€์š” ?

  • @FeignClient ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ kakaoApi ์„œ๋ฒ„์™€ ํ†ต์‹ ํ•ด๋ดค์Šต๋‹ˆ๋‹ค.

  • kakaoAuth๊ด€๋ จํ•œ ๋กœ์ง์„ AuthService์— ๋„ฃ์œผ๋ฉด ์ฝ”๋“œ๊ฐ€ ์ง€์ €๋ถ„ํ•ด์ ธ์„œ, kakaoAuth๋ฅผ implementationํ•œ KakaoAuthImplํด๋ž˜์Šค๋ฅผ ๊ตฌํ˜„ํ•˜์—ฌ kakaoAuth์— ํ•„์š”ํ•œ ๋ฉ”์„œ๋“œ๋ฅผ ๋ฌถ์–ด๋†จ์Šต๋‹ˆ๋‹ค.

  • ๋˜ํ•œ ์ด์Šˆ๊ฐ€ ์žˆ์—ˆ๋Š”๋ฐ, Authentication์—์„œ ProviderType์ด spring์˜ enumํƒ€์ž…์œผ๋กœ ๋˜์–ด, DB ์ˆซ์ž๋กœ ์ธ์‹๋๊ธฐ ๋•Œ๋ฌธ์—, String์œผ๋กœ ๋ณ€ํ™˜ํ•ด์ฃผ๋Š” ์–ด๋…ธํ…Œ์ด์…˜์„ AuthenticationProvider, ProviderType์— ์ถ”๊ฐ€ํ•˜์—ฌ ์ด์Šˆ๋ฅผ ํ•ด๊ฒฐํ–ˆ์Šต๋‹ˆ๋‹ค.

  • ๋˜ํ•œ AuthenticationProvider๋ฅผ Spring jpa ๋ฉ”์†Œ๋“œ๋ฅผ ํ†ตํ•ด ๊ฐ€์ ธ์˜ฌ ๋•Œ userํ”„๋กœํผํ‹ฐ์˜ ์ง€์—ฐ๋กœ๋”ฉ์œผ๋กœ ์ธํ•ด, ํ”„๋ก์‹œ ๊ฐ์ฒด๊ฐ€ ๊ฐ€์ ธ์™€์ ธ, AuthenticationProviderRepository์—์„œ fetchjoin์„ ํ†ตํ•ด ๊ฐ–๊ณ ์˜ฌ ์ˆ˜ ์žˆ๊ฒŒ ๊ตฌํ˜„ํ–ˆ์Šต๋‹ˆ๋‹ค.

โœ๏ธ ๊ด€๋ จ ์ด์Šˆ

@wlwpfh wlwpfh requested review from wlwpfh and dragontaek-lee and removed request for wlwpfh June 26, 2023 03:40
@wlwpfh wlwpfh assigned GaHee99 and unassigned dragontaek-lee and wlwpfh Jun 26, 2023
Copy link
Contributor

@wlwpfh wlwpfh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ˆ˜๊ณ ํ•˜์…จ์Šต๋‹ˆ๋‹ค! ! ๐Ÿ‘๐Ÿ‘๐Ÿ‘

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;

@FeignClient(name = "kakaoAuth", url = "https://kapi.kakao.com")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์—ฌ๊ธฐ url์„ yml์— ๋”ฐ๋กœ ๋นผ์ฃผ๋ฉด ์ข‹์„ ๊ฑฐ ๊ฐ™์•„์š”!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋„ต!

return kakaoUser;
}

private boolean checkSocialUser(KakaoUserResponseDto kakaoUser){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋ฆฌํ„ด๊ฐ’์„ ์‚ฌ์šฉํ•˜์ง€ ์•Š์œผ๋‹ˆ๊นŒ void๋Š” ์–ด๋–ค๊ฐ€์š”?!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์•„์ฃผ ์ข‹์Šต๋‹ˆ๋‹ค.

Comment on lines +42 to +48
private KakaoUser checkSocialUserHaveEmail(KakaoUserResponseDto kakaoUserResponseDto){
String email = "";
if (kakaoUserResponseDto.kakao_account().email() != null) {
email = kakaoUserResponseDto.kakao_account().email();
}
return KakaoUser.of(kakaoUserResponseDto.id(), email);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋Œ€์™•๊ผผ๊ผผ!!! ๐Ÿ‘๐Ÿ‘๐Ÿ‘๐Ÿ‘

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์˜จ๋ƒ๊ฐ€ ๋…ธ๋“œ๋กœ ๊ตฌํ˜„ํ•œ๊ฑฐ ๊ทธ๋Œ€๋กœ ๋กœ์ง ์ž‘์„ฑํ•œ๊ฑฐ์–Œ~
์ฒด๊ณ ์ง€์˜

Comment on lines 43 to 48
AuthSocialCheckResponseDto response ;
if (existUser==null)
response = AuthSocialCheckResponseDto.of(user.userId(),user.email(),false);
else{
response = AuthSocialCheckResponseDto.of(user.userId(),user.email(),true);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๐Ÿ‘๐Ÿ‘

import java.util.Optional;

public interface AuthenticationProviderRepository extends JpaRepository<AuthenticationProvider, Long> {
@EntityGraph(attributePaths = "user")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์•Œ์•„๊ฐ€์š”! ๐Ÿ‘

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๊ฐ์‚ฌํ•ด์š”!!

Comment on lines 84 to 86
Optional<AuthenticationProvider> authenticationProvider = authenticationProviderRepository
.findByIdAndProvider(kakaoUser.userId(),
kakaoUser.providerType());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ด ๋ถ€๋ถ„ ํ•œ ์ค„์ด์–ด๋„ ๋  ๊ฑฐ ๊ฐ™์•„์š”!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋„ต ๊ฐ€๋…์„ฑ๋•Œ๋ฌธ์— ์—ฌ๋Ÿฌ์ค„๋กœ ์ป๋Š”๋ฐ, ํ•œ์ค„๋กœ ๊ณ ์น˜๊ฒ ์Šด๋‹น~

Copy link
Member

@dragontaek-lee dragontaek-lee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ฝ”๋“œ ์ •๋ง ์ž˜๋ดค์Šต๋‹ˆ๋‹ค~!! FeignClient ํฅ๋ฏธ๋กญ๋„ค์šฉ!!
์ œ๊ฐ€ ๋ฉ˜์…˜ ๋‚จ๊ฒจ๋†“์€ ๋ถ€๋ถ„ ์˜๊ฒฌ ์ฃผ์„ธ์š”~! ๋กœ์ง์€ ๋‹ค ์ •๋ง ์ข‹์€๋ฐ, ์กฐ๊ธˆ ์ง€์ €๋ถ„ํ•ด๋ณด์ผ ์ˆ˜ ์žˆ๋Š” ๋ถ€๋ถ„๋“ค ์ˆ˜์ •ํ•˜๋ฉด ์ข‹์„๊ฑฐ ๊ฐ™์•„์š”

return kakaoUser;
}

private boolean checkSocialUser(KakaoUserResponseDto kakaoUser){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chckSocialUser๋Š” Checkํ•œ๋‹ค๋Š” ์—ญํ• ๋งŒ ๋ถ€์—ฌํ•˜๊ณ (true / false ๋ฐ˜ํ™˜) ์œ„์— getKakaoUser์—์„œ throwํ•˜๋Š”๊ฒŒ ๋” ๋ฐ”๋žŒ์งํ•  ๊ฑฐ ๊ฐ™์•„์š”! ๋ฉ”์†Œ๋“œ์˜ ์ด๋ฆ„๊ณผ ์—ญํ• ์ด ๋ช…ํ™•ํ•œ๊ฒŒ ์ค‘์š”ํ•˜๋‹ค ์ƒ๊ฐํ•ด์„œ ๋‚จ๊น๋‹ˆ๋‹ค!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋„ต! ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค!

return true;
}

private KakaoUser checkSocialUserHaveEmail(KakaoUserResponseDto kakaoUserResponseDto){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

email ๋“ฑ๋ก๋˜์–ด์žˆ์Œ ๊ฐ–๋‹ค ์“ฐ๊ณ , ์—†์œผ๋ฉด ์•ˆ์“ฐ๋Š” ํ˜•์‹์ผ๊นŒ์š”?!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋„ต๋งž์Šต๋‹ˆ๋‹น!

}
}

public KakaoUser getKakaoUser(String accessToken){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ด๊ฑฐ๋Š” ์–ด๋””์„œ ์“ฐ๋Š”๊ฑธ๊นŒ์š”? interface๋ฅผ ๋งŒ๋“ค์—ˆ์œผ๋ฉด Overrideํ•ด์•ผ ์˜๋ฏธ๊ฐ€ ์žˆ๋‹ค๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

authService -> kakao->check์— ์“ฐ์ž…๋‹ˆ๋‹ค!
kakaoAuth๋ฅผ interface๋กœ ๊ตฌํ˜„ํ•œ ์ด์œ ๋Š” ,@FeignClient์˜ ๋ฌธ๋ฒ•๋•Œ๋ฌธ์ด๊ณ ,
kakaoUser์„ ๊ฐ–๊ณ ์˜ค๋Š” ๋กœ์ง์„ ํ•œ ํŒŒ์ผ๋กœ ์—ฎ๊ธฐ์œ„ํ•ด KakaoAuthImpl์„ ๋งŒ๋“ค์—ˆ์Šต๋‹ˆ๋‹น,
์ธํ„ฐํŽ˜์ด์Šค๋ฅผ implementํ•œ ์ด์œ ๋Š” @FeignClient๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ์ž…๋‹ˆ๋‹ค!

@@ -33,4 +35,17 @@ public ResponseEntity<ApiResponse> signInUser(@RequestBody AuthSignInRequestDto
AuthSignInResponseDto response = authService.signInUser(request);
return ResponseEntity.ok(ApiResponse.success(SUCCESS_SIGN_IN.getMessage(), response));
}

@PostMapping("/kakao/check")
public ResponseEntity<ApiResponse> findSocialUser(@RequestBody AuthSocialCheckRequestDto request) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋ง์”€ํ•˜์‹ ๋Œ€๋กœ ํ•ด๋‹น ๋กœ์ง ๋‹ค service๋กœ ๋„˜๊ธฐ๋Š”๊ฒŒ ๋งž๋‹ค๊ณ  ์ƒ๊ฐํ•ด์š”.
getUser + findByKey ๋กœ์ง๋„ ํ•ฉ์ณ์„œ ๋ฐ˜ํ™˜ํ•˜๋„๋ก ํ•ฉ์‹œ๋‹ค!!! ์˜ˆ์™ธ์ฒ˜๋ฆฌ๋„ Service์—์„œ ํ•˜๊ณ ์šฉ~! ์ปจํŠธ๋กค๋Ÿฌ๋Š” ์ „๋‹ฌ์—๋งŒ ์‹ ๊ฒฝ์“ฐ๋„๋ก ํ•ฉ์‹œ๋‹น

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋„ต์•Œ๊ฒ ์Šต๋‹ˆ๋‹น!

import java.util.Optional;

public interface AuthenticationProviderRepository extends JpaRepository<AuthenticationProvider, Long> {
@EntityGraph(attributePaths = "user")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ด๊ฑฐ ์–ด๋–ค ์–ด๋…ธํ…Œ์ด์…˜์ธ์ง€ ์ž˜ ๋ชฐ๋ผ์„œ ๊ฐ„๋žตํ•˜๊ฒŒ ์„ค๋ช… ๋ถ€ํƒ๋“œ๋ ค๋„ ๋ ๊นŒ์šฉ?!~์ƒˆ๋กœ ๋ฐฐ์šด๋‹ค ์•ผํ˜ธ!


public User findByKey(KakaoUser kakaoUser){
Optional<AuthenticationProvider> authenticationProvider = authenticationProviderRepository
.findByIdAndProvider(kakaoUser.userId(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ด๊ฑฐ ๊ฐœํ–‰์ด ์™œ์ด๋Ÿฌ์ฃ  ใ…‹ใ…‹ใ…‹ํใ… ใ… ใ…  ํ•˜ํ•ซ..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์•— ์ผ๋ถ€๋กœ ์ž˜๋ณด์ผ๊ฒƒ๊ฐ™์•„์„œ ์ด๋ ‡๊ฒŒ ํ–ˆ๋Š”๋ฐ ํ•œ์ค„๋กœ ํ•ฉ์น˜๊ฒ ์Šด๋‹น~

.findByIdAndProvider(kakaoUser.userId(),
kakaoUser.providerType());
// ์นด์นด์˜ค ๊ณ„์ •์€ ํ™•์ธ, ์šฐ๋ฆฌ ์„œ๋น„์Šค์— ์ด๋ฏธ ๋กœ๊ทธ์ธํ•จ
if(authenticationProvider.isPresent()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋ง์”€๋“œ๋ ธ๋“ฏ์ด ์œ„์— getUser์™€ findByKey ํ•ฉ์น˜๋Š”๊ฒŒ ์ข‹์„๊ฑฐ ๊ฐ™์•„์š”!
response = AuthSocialCheckResponseDto.of(user.userId(),user.email(),false);
response = AuthSocialCheckResponseDto.of(user.userId(),user.email(),true);

์ด๊ฑฐ ์ฐจ์ด๊ฐ€ true, false๋ฐ–์— ์—†๋Š”๋ฐ, isPresent์ผ๋•Œ true DTO ๋ฐ˜ํ™˜ํ•˜๊ณ  ์•„๋‹๋•Œ๋Š” false DTO ๋ฐ˜ํ™˜ํ•˜๋ฉด ๋ ๊ฑฐ ๊ฐ™์•„์š”!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋„ต!!! ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค!

Copy link
Contributor

@wlwpfh wlwpfh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ˆ˜๊ณ ํ•˜์…จ์Šต๋‹ˆ๋‹ค ! ! ! ๐Ÿ‘๐Ÿ‘

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

์นด์นด์˜ค ์ค‘๋ณต ์ฒดํฌ
3 participants