Skip to content

Latest commit

 

History

History
55 lines (44 loc) · 2.39 KB

File metadata and controls

55 lines (44 loc) · 2.39 KB

dev.gitlive.firebase:firebase-auth 에서 마이그레이션

이미 dev.gitlive.firebase:firebase-auth 를 사용 중이며 io.moondeveloper:moon-firebase-auth-kmp 로 이전하려는 경우의 대응 가이드입니다. 핵심 이점: SPI 우선 표면 (AuthProvider) 으로 Fake 교체가 쉽고, Android + iOS + Desktop 에서 동일한 DI 모듈을 사용합니다.

API 매핑

gitlive API moon-firebase-auth-kmp
Firebase.auth.signInWithEmailAndPassword(email, pw) AuthProviderauth.signInWithEmailPassword(email, pw)
Firebase.auth.currentUser (스냅샷) auth.currentUser: StateFlow<AuthUser?> (관찰 가능)
Firebase.auth.authStateChanged (Flow) auth.currentUser (StateFlow 가 둘을 대체)
Firebase.auth.signOut() auth.signOut()
Firebase.auth.createUserWithEmailAndPassword(...) auth.createUser(email, pw)

Before

// gitlive: 기능 코드가 Firebase 를 직접 참조합니다.
class AuthRepo {
    private val auth = Firebase.auth
    suspend fun signIn(email: String, pw: String) =
        auth.signInWithEmailAndPassword(email, pw)
    val user get() = auth.currentUser
}

After

// moon-firebase-auth-kmp: 기능 코드가 L1 SPI 에만 의존합니다.
class AuthRepo(private val auth: AuthProvider) {
    suspend fun signIn(email: String, pw: String) =
        auth.signInWithEmailPassword(email, pw)
    val user: StateFlow<AuthUser?> get() = auth.currentUser
}

마이그레이션 단계

  1. commonMain 에서 dev.gitlive.firebase:firebase-auth 를 제거합니다.
  2. io.moondeveloper:moon-firebase-auth-kmp:1.0.0 을 추가하고 Maven 자격증명을 설정합니다 (auth/ko.md 참조).
  3. Firebase.auth 직접 참조를 Koin 주입 AuthProvider 로 교체합니다.
  4. authStateChanged 수집 코드를 currentUser.collect { ... } 로 전환합니다.
  5. 기존 인증 테스트를 Fake AuthProvider 로 실행하세요. Firebase 에뮬레이터 보일러플레이트가 더 이상 필요 없습니다.

주의사항

  • AuthUser 의 필드는 Firebase FirebaseUser 표면의 엄격한 부분집합입니다. 공급자별 메타데이터에 의존한다면 별도의 Koin 제공 어댑터로 소비하세요.
  • signOut() 은 moon-firebase-auth-kmp 에서 suspend 입니다 (리턴 전에 대기 중인 쓰기를 플러시합니다).