I've been trying to use Reso Coder's Flutter adaptation of Uncle Bob's Clean Architecture.
My app connects to an API, and most requests (other than logging in) require an authentication token. Furthermore, upon logging in, user profile information (like a name and profile picture) is received.
I need a way to save this data upon login, and use it in both future API requests and my app's UI.
As I'm new to Uncle Bob's Clean Architecture, I'm not quite sure where this data belongs. Here are the ideas I've come up with, all involving storing the data in a User object:
Store the
Userin the repository layer, in anauthenticationfeature directory. Other repository-level methods can pass it to the appropriate datasource methods.This seems to make the most sense; other repository-level methods that call other API calls can use the stored
Usereasily, passing it to methods in the data source layer.If this is the way to go, I'm not quite sure how other features (that use the API) would access the
User- is it okay to have a repository depend on another, and pass theauthenticationrepository to the new feature repository?Store the
Userin the repository layer, in anauthenticationfeature directory. Other (non-login) usecases can depend on both this repository and on one relevant to their own feature, passing theUserto their repository methods.This is also breaking the vertical feature barrier, but it may be cleaner then idea 1.
For both these ideas, here's what my repository looks like:
abstract class AuthenticationRepository {
/// The current user.
User get currentUser;
/// True if logged in.
bool get loggedIn;
/// Logs in, saving the [User].
Future<void> login(AuthenticationParams params);
/// Logs out, disposing of the [User].
Future<void> logout();
/// Same as [logout], but logs out of all devices.
Future<void> logoutAll();
/// Retrieves stored login credentials.
Future<AuthenticationParams> retrieveStoredCredentials();
}
Are these ideas "valid", and are there any better ways of doing it?