Skip to content

[Feat] #7 - 카카오 로그인 구현 #9

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

Merged
merged 9 commits into from
Jan 6, 2022
Merged

[Feat] #7 - 카카오 로그인 구현 #9

merged 9 commits into from
Jan 6, 2022

Conversation

L-j-h-c
Copy link
Member

@L-j-h-c L-j-h-c commented Jan 5, 2022

🌴 PR 요약

🌱 작업한 브랜치

🌱 작업한 내용

  • 카카오 소셜로그인 기능 구현(톡로그인, 계정로그인)
  • 로그아웃, 연결 끊기 기능 구현
  • 토큰 보유 유무 확인 기능
  • userId, 프로필이미지, 이메일, 닉네임 받아오기

📌 참고 사항

레이아웃은....너그럽게...봐주세요

📸 스크린샷

기능 스크린샷
데이터 픽업 스크린샷 2022-01-05 오후 5 19 45

📮 관련 이슈

@L-j-h-c L-j-h-c self-assigned this Jan 5, 2022
@L-j-h-c L-j-h-c merged commit 9e530d7 into develop Jan 6, 2022
Copy link
Member

@hyun99999 hyun99999 left a comment

Choose a reason for hiding this comment

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

LZTM 😎

Comment on lines +9 to +10
pod 'KakaoSDKUser' # 카카오 로그인
pod 'KakaoSDKUser' # 사용자 관리
Copy link
Member

Choose a reason for hiding this comment

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

# 전체 추가
pod 'KakaoSDK'

# or

# 필요한 모듈 추가
pod 'KakaoSDKCommon'  # 필수 요소를 담은 공통 모듈
pod 'KakaoSDKAuth'  # 사용자 인증
pod 'KakaoSDKUser'  # 카카오 로그인, 사용자 관리
pod 'KakaoSDKTalk'  # 친구, 메시지(카카오톡)
pod 'KakaoSDKStory'  # 카카오스토리 
pod 'KakaoSDKLink'  # 메시지(카카오링크)
pod 'KakaoSDKTemplate'  # 메시지 템플릿 
pod 'KakaoSDKNavi'  # 카카오내비

이렇다구 하는데
사용자 인증 역할을 하는 'KakaoSDKAuth' 도 필요해요!

그런데 KakaoSDKUser 만 적어줘도 auth, common, user 이렇게 세개가 인스톨되더라구요 그래서 정상적으로 임포트를 할 수 있었던 것 같습니당!

Copy link
Member Author

Choose a reason for hiding this comment

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

아아 이런 실수를,,,,ㅋㅋㅋㅋㅋㅋㅋ...
그래도 덕분에 kakaoSDKUser를 임포트하면 auth, common, user가 인스톨된다는 점 알아갑니다!

super.viewDidLoad()

setText()
// Do any additional setup after loading the view.
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
Member Author

Choose a reason for hiding this comment

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

주석..제거..메모

Comment on lines +69 to +75
let url = profile!
DispatchQueue.global().async {
let data = try? Data(contentsOf: url)
DispatchQueue.main.async {
self.profileImageView.image = UIImage(data: data!)
}
}
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
Member

Choose a reason for hiding this comment

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

도약갈겨보자면 킹피셔 사용해서 킹피셔 깃헙에 나와있는 기본예제 공부도 좋겠네여!!

Copy link
Member Author

Choose a reason for hiding this comment

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

킹피셔로 refactoring 갈겨 보겠..읍니다!

Comment on lines +109 to +113
let nickname = user?.kakaoAccount?.profile?.nickname
let email = user?.kakaoAccount?.email
let userId = user?.id
let birthday = user?.kakaoAccount?.birthday
let profile = user?.kakaoAccount?.profile?.profileImageUrl
Copy link
Member

Choose a reason for hiding this comment

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

이렇게 하면 nickname 이 무슨 타입인지 모르니까
let nickname: String? = user?.kakao... 이런식으로 가져가도 좋을거 같네여!

Copy link
Member Author

Choose a reason for hiding this comment

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

타입 명시 잘 해놓겠슴당!

private func getUserInfo() {

// ✅ 사용자 정보 가져오기
UserApi.shared.me() {(user, error) in
Copy link
Member

Choose a reason for hiding this comment

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

저희는 서버에 이제 회원 고유 값 user.id 를 보내면 됩니당(물론 이 방법은 클라에서 유저 고유 값을 전해주는 방법. 서버로 앞서 얻었던 oauthToken 을 보내주면 서버에서 토큰을 해체하는 방법도 있습니다! 난이도는 전자가 훨씬 쉬워서 앱잼 내에서는 전자의 방법으로 진행하자고 조언했구 클라입장에서는 user.id 를 보내나 oauthToken 을 보내나 코스트는 같기 때문에 동일한 난이도라고 생각되네여!)

Copy link
Member Author

Choose a reason for hiding this comment

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

클라가 회원의 정보를 얻는 방법

  1. user.id를 서버에 보내서 정보를 얻어오는 방법
  2. oauthToken 자체를 보내서 서버에 해체를 부탁하는 방법
  • 클라 난이도는 같지만 서버가 힘듬

1의 경우에는 userDefault에 저장해서 진행하는 것이 맞을까요?
@hyun99999

Copy link
Member

Choose a reason for hiding this comment

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

그것도 방법이지만 애플에는 키체인이라는 것이 있죠! 그래서 토큰 혹은 암호 민감한 정보 같은 경우 키체인이 적합하다고 해여 쓰다보니 이번에는 userDefaults 말고 키체인해 넣어보는건 어떨까요?? @yangsubinn

Copy link
Member

Choose a reason for hiding this comment

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

좋슴니다! 더 적합한 것 같아요!

}
}

private func getUserInfo() {
Copy link
Member

Choose a reason for hiding this comment

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

private 좋아요!
제가 만약에 다시 네이밍을 한다면 getUserInfo 라는 네이밍은 화면전환에 대한 의미를 띈다고 생각하지 않아요 그래서 주석을 쓰게 되구여 그런데 주석은 보통 블럭 내에서 보다는 블럭 밖에서 써주는 것이 맞다라고 추천하고 있어여! 블럭내의 코드는 최대한 설명없이 이해될 수 있도록 말이죠!

Copy link
Member

Choose a reason for hiding this comment

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

그런데 이처럼 연습이나 설명을 할때는 좋은 방법 같아요! 그래서 제가 다시 네이밍을 하게 된다면 화면전환 코드를 pushToLogoutVC 라고 따로 빼두고 getUserInfo 안에서 가져다 쓸거 같아여!

Copy link
Member Author

Choose a reason for hiding this comment

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

주석은 블럭 밖에... + 함수는 기능별로 잘 정리해서 네이밍~~!
꿀팁 감사합니당!!

@hyun99999
Copy link
Member

hyun99999 commented Jan 7, 2022

@yangsubinn @L-j-h-c
앱잼내에서 자동로그인을 구현할 때는 앱델리게이트에서 앱을 실행할 때 카카오인지 애플인지 구분하고(userDefaults 를 통해서)

  • 카카오라면 토큰 존재 여부를 알아보는 AuthApi.hasToken() 라는 메서드로 현재 토큰이 있는지 그리고 isInvalidTokenError() 메서드로 유효한 토큰이 있는지!(=카카오와 앱이 연동이 되어있는가!) 확인하고 분기처리.
  • 애플이라면 getCredentialState(forUserID:completion:)` 메서드로 애플과 앱이 연동이 되어있는지 확인하고 분기처리.
    이와 같이 진행되도록 하면 될 것 같습니다

@L-j-h-c L-j-h-c deleted the feature/#7 branch January 9, 2022 17:36
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.

[Feat] 카카오톡 로그인 구현
3 participants