bk9735732777
07/09/2025, 5:09 PMinterface GoogleSignInPlatform {
suspend fun signIn(): GoogleSignInResult
suspend fun signOut(): Boolean
fun isSignedIn(): Boolean
suspend fun getCurrentUser(): GoogleUserInfo?
}
Can i get some help herebk9735732777
07/09/2025, 5:10 PMChrimaeon
07/09/2025, 6:18 PMbk9735732777
07/10/2025, 3:03 AMimport Foundation
import GoogleSignIn
import UIKit
import ComposeApp
// This class implements the GoogleSignInPlatform interface from Kotlin
class GoogleSignInBridge: GoogleSignInPlatform {
func getCurrentUser(completionHandler: @escaping (GoogleUserInfo?, (any Error)?) -> Void) {
guard let currentUser = GIDSignIn.sharedInstance.currentUser else {
completionHandler( nil , nil)
}
// Extract user information
let userId = currentUser.userID ?? ""
let email = currentUser.profile?.email ?? ""
let displayName = currentUser.profile?.name ?? ""
let photoUrl = currentUser.profile?.imageURL(withDimension: 200)?.absoluteString
let idToken = currentUser.idToken?.tokenString
// Create and return GoogleUserInfo
completionHandler( GoogleUserInfo(
userId: userId,
email: email,
displayName: displayName,
photoUrl: photoUrl,
idToken: idToken
),nil)
}
func getCurrentUser() async throws -> GoogleUserInfo? {
guard let currentUser = GIDSignIn.sharedInstance.currentUser else {
return nil
}
// Extract user information
let userId = currentUser.userID ?? ""
let email = currentUser.profile?.email ?? ""
let displayName = currentUser.profile?.name ?? ""
let photoUrl = currentUser.profile?.imageURL(withDimension: 200)?.absoluteString
let idToken = currentUser.idToken?.tokenString
// Create and return GoogleUserInfo
return GoogleUserInfo(
userId: userId,
email: email,
displayName: displayName,
photoUrl: photoUrl,
idToken: idToken
)
}
func signIn(completionHandler: @escaping (GoogleSignInResult?, (any Error)?) -> Void) {
guard let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
let rootViewController = windowScene.windows.first?.rootViewController else {
completionHandler(GoogleSignInResult(
isSuccess: false,
userInfo: nil,
errorMessage: "No root view controller found"
), nil)
}
GIDSignIn.sharedInstance.signIn(withPresenting: rootViewController){ result, error in
if let user = result?.user {
let userId = user.userID ?? ""
let email = user.profile?.email ?? ""
let displayName = user.profile?.name ?? ""
let photoUrl = user.profile?.imageURL(withDimension: 200)?.absoluteString
let idToken = user.idToken?.tokenString
// Create GoogleUserInfo
let userInfo = GoogleUserInfo(
userId: userId,
email: email,
displayName: displayName,
photoUrl: photoUrl,
idToken: idToken
)
// Return successful result
completionHandler(GoogleSignInResult(
isSuccess: true,
userInfo: userInfo,
errorMessage: nil
), nil)
}
}
}
func signIn() async throws -> GoogleSignInResult {
guard let windowScene = await UIApplication.shared.connectedScenes.first as? UIWindowScene,
let rootViewController = await windowScene.windows.first?.rootViewController else {
return GoogleSignInResult(
isSuccess: false,
userInfo: nil,
errorMessage: "No root view controller found"
)
}
do {
// Attempt to sign in
let result = try await GIDSignIn.sharedInstance.signIn(withPresenting: rootViewController)
// Extract user information
let user = result.user
let userId = user.userID ?? ""
let email = user.profile?.email ?? ""
let displayName = user.profile?.name ?? ""
let photoUrl = user.profile?.imageURL(withDimension: 200)?.absoluteString
let idToken = user.idToken?.tokenString
// Create GoogleUserInfo
let userInfo = GoogleUserInfo(
userId: userId,
email: email,
displayName: displayName,
photoUrl: photoUrl,
idToken: idToken
)
// Return successful result
return GoogleSignInResult(
isSuccess: true,
userInfo: userInfo,
errorMessage: nil
)
} catch {
// Return error result
return GoogleSignInResult(
isSuccess: false,
userInfo: nil,
errorMessage: error.localizedDescription
)
}
}
func signOut(completionHandler: @escaping (KotlinBoolean?, (any Error)?) -> Void) {
GIDSignIn.sharedInstance.signOut()
completionHandler(KotlinBoolean(bool: true), nil)
}
func signOut() async throws -> KotlinBoolean {
GIDSignIn.sharedInstance.signOut()
return KotlinBoolean(bool: true)
}
func isSignedIn() -> KotlinBoolean {
let isSignedIn = GIDSignIn.sharedInstance.hasPreviousSignIn()
return KotlinBoolean(bool: isSignedIn)
}
}
This is my swift codebk9735732777
07/10/2025, 3:04 AMBharat Kumar
07/10/2025, 4:13 AM