This auth_client
package defines the abstract interface (AuthClient
) for authentication operations within the Flutter News App Full Source Code Toolkit. It provides a clear contract that concrete implementations (e.g., API clients, Firebase clients, in-memory mocks) must adhere to. The interface supports both an email+code password-less authentication and an anonymous authentication flow, ensuring consistent and flexible authentication mechanisms across the Flutter mobile app, web dashboard, and Dart Frog backend API.
This package offers a comprehensive set of features for managing authentication operations.
🧱 Core Functionality
AuthClient
Abstract Class: Defines a generic, provider-agnostic interface for all authentication operations.authStateChanges
Stream: AStream<User?>
that emits the current authenticatedUser
ornull
whenever the authentication state changes (sign-in, sign-out). This is ideal for reactive UI updates.getCurrentUser()
: An asynchronous methodFuture<User?>
to retrieve the currently signed-inUser
, if any.
requestSignInCode(String email, {bool isDashboardLogin = false})
: Initiates the passwordless sign-in flow. It is context-aware, supporting both standard sign-in and privileged dashboard login with appropriate validation.verifySignInCode(String email, String code, {bool isDashboardLogin = false})
: Verifies the email code to complete the sign-in/sign-up process. For dashboard login, it strictly performs a login and does not create new accounts. Returns aFuture<AuthSuccessResponse>
.signInAnonymously()
: Signs the user in anonymously, creating a temporary user identity on the backend and returning aFuture<AuthSuccessResponse>
containing the anonymousUser
and token.signOut()
: Signs out the current user (whether authenticated normally or anonymously).linkEmail(String email)
: Initiates the process of linking an email to an existing anonymous account.verifyLinkEmail(String code)
: Completes the email linking process by verifying the code. On success, it returns aFuture<AuthSuccessResponse>
with the now-permanent user and a new token.deleteAccount()
: Allows an authenticated user to delete their own account.
HttpException
Propagation: Implementations must map underlying errors to appropriateHttpException
subtypes (defined incore
), ensuring consistent and predictable error management across the application layers.
💡 Your Advantage: This package provides a clear, abstract interface for authentication, decoupling your application from specific authentication service providers. This design promotes flexibility, testability, and maintainability, allowing you to easily integrate and swap authentication solutions as needed, while ensuring consistent user management and error handling.
This auth_client
package is an integral part of the Flutter News App Full Source Code Toolkit. For comprehensive details regarding licensing, including trial and commercial options for the entire toolkit, please refer to the main toolkit organization page.