From a3bad30c2a504dd0c0b0288a4e42dd37fc47209e Mon Sep 17 00:00:00 2001 From: Martin Bonnin Date: Fri, 19 Apr 2024 20:28:03 +0200 Subject: [PATCH] unbreak wearos signin (#294) --- wearApp/build.gradle.kts | 2 +- .../wear/ui/main/MainViewModel.kt | 11 +++++++--- .../wear/ui/signin/GoogleSignInViewModel.kt | 21 +++++++------------ 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/wearApp/build.gradle.kts b/wearApp/build.gradle.kts index b7b81f46..bf74bb38 100644 --- a/wearApp/build.gradle.kts +++ b/wearApp/build.gradle.kts @@ -62,7 +62,7 @@ dependencies { implementation(libs.androidx.compose.ui.tooling) implementation(libs.wear.compose.navigation) implementation(platform(libs.firebase.bom)) - implementation(libs.firebase.auth.ktx) + implementation(libs.firebase.auth) coreLibraryDesugaring(libs.desugar.jdk.libs) debugImplementation(libs.compose.ui.tooling) diff --git a/wearApp/src/main/java/fr/paug/androidmakers/wear/ui/main/MainViewModel.kt b/wearApp/src/main/java/fr/paug/androidmakers/wear/ui/main/MainViewModel.kt index b3c9e41b..3c2d03b0 100644 --- a/wearApp/src/main/java/fr/paug/androidmakers/wear/ui/main/MainViewModel.kt +++ b/wearApp/src/main/java/fr/paug/androidmakers/wear/ui/main/MainViewModel.kt @@ -6,8 +6,8 @@ import androidx.lifecycle.AndroidViewModel import androidx.lifecycle.viewModelScope import com.google.android.gms.auth.api.signin.GoogleSignIn import com.google.android.gms.auth.api.signin.GoogleSignInOptions -import com.google.firebase.auth.ktx.auth -import com.google.firebase.ktx.Firebase +import dev.gitlive.firebase.Firebase +import dev.gitlive.firebase.auth.auth import fr.androidmakers.domain.interactor.GetAgendaUseCase import fr.androidmakers.domain.interactor.GetFavoriteSessionsUseCase import fr.androidmakers.domain.interactor.SyncBookmarksUseCase @@ -17,7 +17,9 @@ import fr.androidmakers.domain.repo.UserRepository import fr.paug.androidmakers.wear.applicationContext import fr.paug.androidmakers.wear.data.LocalPreferencesRepository import fr.paug.androidmakers.wear.ui.session.UISession +import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableStateFlow @@ -116,6 +118,7 @@ class MainViewModel( } } + @OptIn(DelicateCoroutinesApi::class) fun signOut() { val googleSignInClient = GoogleSignIn.getClient( applicationContext, @@ -125,7 +128,9 @@ class MainViewModel( ) googleSignInClient.signOut() googleSignInClient.revokeAccess() - Firebase.auth.signOut() + GlobalScope.launch { + Firebase.auth.signOut() + } _user.value = null } diff --git a/wearApp/src/main/java/fr/paug/androidmakers/wear/ui/signin/GoogleSignInViewModel.kt b/wearApp/src/main/java/fr/paug/androidmakers/wear/ui/signin/GoogleSignInViewModel.kt index 2a10a103..4253f818 100644 --- a/wearApp/src/main/java/fr/paug/androidmakers/wear/ui/signin/GoogleSignInViewModel.kt +++ b/wearApp/src/main/java/fr/paug/androidmakers/wear/ui/signin/GoogleSignInViewModel.kt @@ -6,11 +6,11 @@ import com.google.android.gms.auth.api.signin.GoogleSignInAccount import com.google.android.gms.auth.api.signin.GoogleSignInOptions import com.google.android.horologist.auth.data.googlesignin.GoogleSignInEventListener import com.google.android.horologist.auth.ui.googlesignin.signin.GoogleSignInViewModel -import com.google.firebase.Firebase -import com.google.firebase.auth.FirebaseAuthException -import com.google.firebase.auth.FirebaseUser -import com.google.firebase.auth.GoogleAuthProvider -import com.google.firebase.auth.auth +import dev.gitlive.firebase.Firebase +import dev.gitlive.firebase.auth.FirebaseAuthException +import dev.gitlive.firebase.auth.FirebaseUser +import dev.gitlive.firebase.auth.GoogleAuthProvider +import dev.gitlive.firebase.auth.auth import fr.androidmakers.domain.model.User import fr.androidmakers.domain.repo.UserRepository import fr.paug.androidmakers.wear.R @@ -36,8 +36,8 @@ class GoogleSignInViewModel( Log.d(TAG, "Google sign in success") val idToken = account.idToken try { - val credential = GoogleAuthProvider.getCredential(idToken!!, null) - Firebase.auth.signInWithCredential(credential).await() + val credential = GoogleAuthProvider.credential(idToken!!, null) + Firebase.auth.signInWithCredential(credential) UserData().userRepository.setUser(Firebase.auth.currentUser) onSignInSuccess() } catch (e: FirebaseAuthException) { @@ -49,13 +49,6 @@ class GoogleSignInViewModel( } ) -private suspend fun FirebaseUser.toUser(): User { - return User( - id = this.uid, - photoUrl = this.photoUrl.toString(), - ) -} - class UserData: KoinComponent { val userRepository: UserRepository by inject() }