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

Feature/jaino/#14 #21

Merged
merged 21 commits into from
Oct 6, 2023
Merged

Feature/jaino/#14 #21

merged 21 commits into from
Oct 6, 2023

Conversation

jeongjaino
Copy link
Member

1. 📄 관련된 이슈 및 소개

#14 Firebase Github 로그인 로직 구현

2. 🔥변경된 점

FirebaseAuth를 활용한 Github 로그인 로직 구현

  1. hasPandingResult -> 백그라운드로 로그인이 처리되는데, 현재 백그라운드에 처리중인 로직이 있는지 체크 함수
  2. signIn -> github auth를 이용한 FirebaseAuth 로그인 로직 구현
  3. hilt, ksp 종속성 / 플러그인 추가 및 셋업
  4. 모듈 추가 domain, model, network

3. 📸 스크린샷(선택)

4. 💡알게된 혹은 궁금한 사항들

린팅 버그 확인 -> (린팅 룰, 버그) #20 수정 예정입니다...

@jeongjaino jeongjaino added 🚀진호🚀 ESTP 정진호 23세 🔥리뷰 기다리는 중🔥 PR을 올리고 코드리뷰를 기다리고 있는 상태입니다. labels Oct 5, 2023
@jeongjaino jeongjaino self-assigned this Oct 5, 2023
@jeongjaino jeongjaino closed this Oct 5, 2023
@jeongjaino jeongjaino reopened this Oct 5, 2023
@jeongjaino jeongjaino closed this Oct 5, 2023
@jeongjaino jeongjaino reopened this Oct 5, 2023
Comment on lines +4 to +7
suspend fun hasPendingResult(): Boolean

suspend fun signIn(email: String): Result<String>
}
Copy link
Member

Choose a reason for hiding this comment

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

함수명 좋네요.

signIn함수는 email만 있으면 되나요 ?.?

Copy link
Member Author

Choose a reason for hiding this comment

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

AuthDataSourceImpl에서 보실 수 있는데, Activity Context를 사용해, Github Login 웹으로 넘어가 비밀번호를 입력하는 것 같아요!

아마 보안상 이슈때문에, 이런것 같아요

Comment on lines 14 to 19
@Binds
@Singleton
abstract fun provideAuthDataSource(
authDataSourceImpl: AuthDataSourceImpl
): AuthDataSource
}
Copy link
Member

Choose a reason for hiding this comment

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

오호라 Provides가 아니라 Binds를 쓰시네요.
혹시 Binds 쓰시는 이유가 따로 있나요 ?

Binds는 외부 라이브러리를 지원못하는 걸로 알고있어서요.

Provides쓰면 다 해결되자나요 하하

Copy link
Member Author

Choose a reason for hiding this comment

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

하하하하하 습관적으로 Binds 처리해버렸군요... 생각해보니까 협업할 때 Provides랑 Binds를 같이쓸지도 정했어야겠네요...

사실 아시겠지만 Provides랑 Binds랑 정말 뜨거운 감자입니다... 구글에 조금만쳐도 댓글에 열뛴 토론하는거 볼 수 있어요 ㅎㅎ..

Dagger에서도 이런거 알고 FAQ에서 명시해놨어요. 근데 사람들도 이거 알고 싸우는 거라 하하 ..
https://dagger.dev/dev-guide/faq.html#why-is-binds-different-from-provides

서로 따지자면,
Binds -> DataSoruce같이 Interface 매핑 전용 어노테이션입니다. 그래서 Provides에 비해 생성되는 파일과 크기가 작고 효율적이에요.

근데 보시다시피, 단일 매개변수 포함밖에 안돼요. 그래서 나머지를 다 Provides 시켜야 해요. AuthDataSourceImpl에서 보실수 있는데, 실제 매개변수가 ActivityContext, FirebaseAuth가 들어있어요. 근데 주입하는 코드는 비어있죠. 그래서 사실 많이 직관적이지 않아요.

그래서 Provides vs Binds 나뉘는게
P : Binds가 인터페이스 전용 매퍼로 엄청 효율적이야!!!
C : 그러면 뭐해, 알아보지 못하잖아. 매개변수 이거 하나하나 다 까볼꺼야??

이렇게 나뉘는듯 해요.. 하하하

Comment on lines +14 to +24
@Module
@InstallIn(SingletonComponent::class)
object NetworkModule {
@Provides
@Singleton
fun providesFirebaseAuth(): FirebaseAuth = Firebase.auth

@Provides
@Singleton
fun providesFirestore(): FirebaseFirestore = Firebase.firestore
}
Copy link
Member

Choose a reason for hiding this comment

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

이쪽은 Provides군요

Copy link
Member Author

Choose a reason for hiding this comment

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

위 설명에 포함되는 내용인 것 같아요!

activityContext, provider.build()
).await()

checkNotNull(result.user).uid
Copy link
Member

Choose a reason for hiding this comment

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

혹시 .uid 부분 설명 가능할까요? 처음보는 키워드라서요.

Copy link
Member Author

Choose a reason for hiding this comment

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

이부분 클린 코드에서 지양하는 기차충돌인것 같아요.
저도 처음 저 코드를 보면 바로 이해가 안될 것 같네요 ㅠㅠ
바로 코드 수정했습니다!!

해당 코드는 FirebaseAuth 메소드를 사용하면 AuthResult라는 값을 반환하는데, 해당 AuthResult에서 FirebaseUser에 접근하는 코드입니다.

FirebaseUser를 통해 회원 정보를 접근하고 해당 유저의 uid, FirebaseAuth를 사용하면 자동으로 userId 식별자를 생성해주는데, 해당 식별자를 반환하는 코드입니다!

로그인 절차가 Github Login을 통해 Firebase Auth를 인증하고, uid를 반환받으면 해당 uid를 가지고 유저 테이블에 uid가 있는지 없는지로 첫회원인지 확인하기 때문에, uid를 반환받도록 했습니다!

나중에 회원가입 로직구현할 때, 받은 uid를 기반으로 테이블 검색 메소드까지 구현할 예정입니당!

Comment on lines +42 to +44
override suspend fun resign(): Result<Unit> {
TODO("Not yet implemented")
}
Copy link
Member

Choose a reason for hiding this comment

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

이 함수는 어떤 역할을 할 함수인가요 ?.?
제가 영어를 잘 못해서....

image

Copy link
Member Author

Choose a reason for hiding this comment

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

하하 회원탈퇴 메소드 네이밍인데, 후보군이

withDraw, resign, cancel, leave 정도 있어서

위에 sign이 중복되는 resign으로 결정했는데, 혹시 다른게 더 나을까요??

Comment on lines +9 to +18
suspend fun <T> Task<T>.await(): T {
return suspendCancellableCoroutine { cont ->
addOnCompleteListener {
if (it.exception != null) {
cont.resumeWithException(it.exception!!)
} else {
cont.resume(it.result, null)
}
}
}
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.

firebase 로직들이 전부 Listener를 통해 Callback을 받도록 되어 있는데, 해당 콜백을 코루틴으로 변경시키는 코드입니다!

코루틴으로 변경시키면서, 다른 코루틴 코드랑 혼용도 할 수 있고,
무엇보다 여러 스코프가 겹치면서 가독성이 떨어지는 이슈도 대응할 수 있어요!

해당 글에 suspendCoroutine에 대해 잘 나와있어요!
https://tourspace.tistory.com/442?category=797357
https://devroach.tistory.com/162

Copy link
Member

@tgyuuAn tgyuuAn left a comment

Choose a reason for hiding this comment

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

코멘트 남겼습니다!

저도 작업 시작 총총...

@tgyuuAn tgyuuAn added 🌟머지 해주세요🌟 코드 리뷰가 완료된 뒤 PR을 올린사람이 Merge를 하면 되는 단계입니다. and removed 🔥리뷰 기다리는 중🔥 PR을 올리고 코드리뷰를 기다리고 있는 상태입니다. labels Oct 5, 2023
@jeongjaino
Copy link
Member Author

리뷰이거 진짜 좋네요...

리뷰 달면서 제 코드 다시 보고, 문제점 바로 찾고 더 좋은 코드로 작성할 수 있는 거같아서 아주 좋습니다!!

@jeongjaino jeongjaino merged commit 8def0ce into develop Oct 6, 2023
@tgyuuAn tgyuuAn changed the title Featurejaino/#14 Feature/jaino/#14 Nov 1, 2023
@tgyuuAn tgyuuAn deleted the featurejaino/#14 branch February 6, 2024 08:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🌟머지 해주세요🌟 코드 리뷰가 완료된 뒤 PR을 올린사람이 Merge를 하면 되는 단계입니다. 🚀진호🚀 ESTP 정진호 23세
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants