signInWithSavedCredentials

abstract suspend fun signInWithSavedCredentials(activity: Activity): AuthUser

Attempts to sign in using credentials saved in Android's Credential Manager.

This method leverages Android's Credential Manager API to retrieve saved credentials (email/password or Google account) and authenticate the user automatically. This enables seamless "one-tap" sign-in without requiring the user to re-enter credentials.

Behavior

  • Shows the Credential Manager UI with saved credentials

  • User selects a saved credential to sign in

  • Authenticates with Firebase using the selected credential

  • Saves/updates the credential in Credential Manager after successful sign-in

Requirements

  • Requires an Activity context for showing the credential picker UI

  • Credentials must have been previously saved via Credential Manager

  • User must have at least one saved credential

Exceptions

  • Throws CancellationException if user cancels the credential picker

  • Throws NoCredentialException if no saved credentials are found

  • Throws FirebaseAuthException if authentication with saved credentials fails

Example

// In your login ViewModel
fun autoSignIn() {
_uiState.updateStateWith {
authRepository.signInWithSavedCredentials(activity)
}
}

Return

The authenticated AuthUser upon successful sign-in

Parameters

activity

The activity instance required for showing the credential picker UI

Throws

CancellationException

if the user cancels the operation

for authentication failures