Skip to content

Commit

Permalink
unbreak wearos signin (#294)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinbonnin authored Apr 19, 2024
1 parent f3a0d52 commit a3bad30
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
2 changes: 1 addition & 1 deletion wearApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -116,6 +118,7 @@ class MainViewModel(
}
}

@OptIn(DelicateCoroutinesApi::class)
fun signOut() {
val googleSignInClient = GoogleSignIn.getClient(
applicationContext,
Expand All @@ -125,7 +128,9 @@ class MainViewModel(
)
googleSignInClient.signOut()
googleSignInClient.revokeAccess()
Firebase.auth.signOut()
GlobalScope.launch {
Firebase.auth.signOut()
}
_user.value = null
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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()
}

0 comments on commit a3bad30

Please sign in to comment.