signInWithGoogle
Signs in an existing user with their Google account using Google Sign-In.
This method initiates the Google Sign-In flow, allowing users to authenticate using their Google account. The Google ID token is then used to authenticate with Firebase.
Process
Shows Google account picker UI
User selects a Google account
Retrieves Google ID token
Authenticates with Firebase using the Google credential
Returns the authenticated user
Requirements
Requires an Activity context for showing the Google Sign-In UI
Google Sign-In must be enabled in Firebase Console
SHA-1 certificate fingerprint must be configured in Firebase
google-services.jsonmust be properly configuredNetwork connectivity is required
Exceptions
CancellationException- User cancelled the Google Sign-In flowApiException- Google Sign-In API errors (invalid configuration, etc.)FirebaseAuthException- Firebase authentication with Google credential failedFirebaseNetworkException- Network connectivity issues
Example
// In your login ViewModel
fun signInWithGoogle() {
_uiState.updateStateWith {
authRepository.signInWithGoogle(activity)
}
}Return
The authenticated AuthUser upon successful sign-in
Parameters
The activity instance required for showing the Google Sign-In UI
Throws
if user cancels the operation
for Google Sign-In or Firebase authentication failures