Overview
TheAuthService class provides authentication functionality using Firebase Authentication. It handles user login, registration, password recovery, and authentication state management.
Location: com.demodogo.ev_sum_2.services.AuthService
Constructor
The authentication repository instance. Defaults to a new
AuthRepository instance.Methods
login
Authenticates a user with email and password.The user’s email address
The user’s password
Exception if authentication fails with mapped Firebase error message
Usage Example
register
Registers a new user with email and password.The new user’s email address
The new user’s password
Exception if registration fails with mapped Firebase error message
Usage Example
recover
Sends a password reset email to the specified email address.The email address to send the password reset link to
Exception if the password reset request fails
Usage Example
logout
Logs out the current user.Usage Example
isLoggedIn
Checks if a user is currently logged in.Boolean - true if a user is logged in, false otherwise
Usage Example
authStateFlow
Provides a Flow that emits authentication state changes.Flow<FirebaseUser?> - A Flow that emits the current FirebaseUser or null when the user is not authenticated
Usage Example
currentEmail
Retrieves the email address of the currently logged-in user.String? - The current user’s email address, or null if not logged in
Usage Example
Error Handling
Always wrap authentication operations in try-catch blocks to handle potential exceptions:See Also
- AuthRepository - Underlying repository for authentication operations
- Firebase Authentication - Official Firebase Auth documentation