Skip to content

Instantly share code, notes, and snippets.

@arulwastaken
Last active August 7, 2025 16:49
Show Gist options
  • Save arulwastaken/a77791243c387684232bf9d7cc8d9b38 to your computer and use it in GitHub Desktop.
Save arulwastaken/a77791243c387684232bf9d7cc8d9b38 to your computer and use it in GitHub Desktop.
package com.codingwitharul.bill_it.common.auth
//....
actual class GoogleAuthenticator() {
@OptIn(ExperimentalForeignApi::class)
actual suspend fun login() = suspendCoroutine<Result<GoogleUser?>> { continuation ->
val rootUiView = UIApplication.sharedApplication
.keyWindow?.rootViewController
if (rootUiView == null) {
continuation.resume(null)
} else {
GIDSignIn.sharedInstance
.signInWithPresentingViewController(rootUiView) { gidSignInResult, nsError ->
if (nsError != null) {
println("Something went wrong during signInWithPresentingViewController $nsError")
} else {
val idToken = gidSignInResult?.user?.idToken
val profile = gidSignInResult?.user?.profile
if (idToken != null) {
registerUserOnFirebase(
idToken.tokenString,
accessToken = gidSignInResult?.user?.accessToken?.tokenString.toString(),
continuation
)
} else {
continuation.resume(null)
}
}
}
}
}
@OptIn(ExperimentalForeignApi::class)
fun registerUserOnFirebase(
idToken: String,
accessToken: String,
continuation: Continuation<String?>
) {
val firebaseAuth = FIRAuth.auth()
val googleAuthProvider = FIRGoogleAuthProvider.credentialWithIDToken(idToken, accessToken)
firebaseAuth.signInWithCredential(googleAuthProvider) { firAuthDataResult, nsError ->
if (nsError != null) {
println("something went wrong signInWithCredential -> ${nsError}")
} else {
val user = firAuthDataResult?.user()
val displayName = user?.displayName()
continuation.resumeWith(Result.success(displayName))
}
}
}
}
package com.codingwitharul.bill_it.common.auth
import androidx.compose.runtime.Composable
actual class GoogleAuthProvider() {
@Composable
actual fun getUiProvider(): GoogleAuthenticator = GoogleAuthenticator()
actual suspend fun signOut() {
// fireabse or custom signOut
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment