Skip to content

Instantly share code, notes, and snippets.

@blakelee
Created May 10, 2025 19:28
Show Gist options
  • Select an option

  • Save blakelee/822a5494c40b0e5f66baafb24675753a to your computer and use it in GitHub Desktop.

Select an option

Save blakelee/822a5494c40b0e5f66baafb24675753a to your computer and use it in GitHub Desktop.
iOS Google Login Kotlin
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