Authentication Use Cases
Use cases encapsulate the business logic for authentication operations following Clean Architecture principles. Each use case represents a single operation that can be performed by the application.LoginUseCase
Handles user login authentication. Location:lib/feature/auth/core/usecase/login_usecase.dart:13
Constructor
The authentication repository implementation
Parameters
LoginParamsUser’s email address
User’s password
Returns
Returns a
Right containing the authentication token on success, or a Left containing a Failure on errorUsage Example
RegisterUseCase
Handles new user registration. Location:lib/feature/auth/core/usecase/register_usecase.dart:23
Constructor
The authentication repository implementation
Parameters
RegisterParamsUser’s display name (used for UI display or username generation)
User’s username
User’s email address
User’s phone number
User’s password
Returns
Returns a
Right containing registration response data on success, or a Left containing a Failure on errorUsage Example
LogoutUseCase
Handles user logout and token cleanup. Location:lib/feature/auth/core/usecase/logout_usecase.dart:6
Constructor
The authentication repository implementation
Parameters
No parameters required (use
NoParams() instance)Returns
Returns a
Right on successful logout, or a Left containing a Failure on errorUsage Example
CheckAuthStatusUseCase
Checks the current authentication status and retrieves the authenticated user. Location:lib/feature/auth/core/usecase/check_auth_status_usecase.dart:8
Constructor
The authentication repository implementation
Parameters
No parameters required (use
NoParams() instance)Returns
Returns a
Right containing the authenticated User (or null if not authenticated) on success, or a Left containing a Failure on errorUsage Example
GetUserFromTokenUseCase
Retrieves user information from an authentication token. Location:lib/feature/auth/core/usecase/get_user_from_token_usecase.dart:8
Constructor
The authentication repository implementation
Parameters
Authentication token
Returns
Returns a
Right containing the User associated with the token on success, or a Left containing a Failure on errorUsage Example
UseCase Base Class
All use cases implement theUseCase<Type, Params> interface.
Location: lib/core/usecase/usecase.dart:5
Type Parameters
The return type of the use case operation
The parameters type required by the use case
Error Handling
All use cases returnEither<Failure, T> which allows for functional error handling:
- Right: Contains the successful result
- Left: Contains a
Failureobject with error information
ServerFailure: Server-side errorsAuthFailure: Authentication-specific errorsNetworkFailure: Network connectivity issues