Last active
August 7, 2025 16:49
-
-
Save arulwastaken/a77791243c387684232bf9d7cc8d9b38 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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