Created
May 10, 2025 19:28
-
-
Save blakelee/822a5494c40b0e5f66baafb24675753a to your computer and use it in GitHub Desktop.
iOS Google Login Kotlin
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
| class IosGoogleAuthentication( | |
| private val supabaseClient: SupabaseClient, | |
| private val application: UIApplication | |
| ) : GoogleAuthentication { | |
| override suspend fun login() { | |
| val token = getToken() | |
| supabaseClient.auth.signInWith(IDToken) { | |
| provider = Google | |
| idToken = token | |
| } | |
| } | |
| private suspend fun getToken(): String = suspendCancellableCoroutine { continuation -> | |
| val controller = application.keyWindow?.rootViewController!! | |
| GIDSignIn.sharedInstance.signInWithPresentingViewController(controller) { result, error -> | |
| if (error != null) { | |
| continuation.resumeWithException(Exception(error.localizedDescription)) | |
| } else { | |
| val token = result?.user?.idToken?.tokenString | |
| if (token != null) { | |
| continuation.resume(token) | |
| } else { | |
| continuation.resumeWithException(Exception("No token")) | |
| } | |
| } | |
| } | |
| } | |
| override suspend fun logout() { | |
| // Do nothing on iOS | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment