Description
In my project, I need to fetch some data related to the authenticated user, and for that I need the userId
of the user. I have an AuthManager
class that gives me the userId
of the authenticated user. I am confused whether to add this AuthManager
class as a member of my UserRepository
implementation, or just get the userId
from AuthManager
outside the repository and provide it when needed. Basically I have 2 options.
Option 1:
Add AuthManager
as a member to the UserRepository
implementation. UserRepository
will contain functions like getAuthenticatedUserFirstName()
, getAuthenticatedUserLastName()
etc. In the implementations of these functions use the AuthManager
to get the necessary userId
internally.
Option 2:
Leave out AuthManager
from the repository. UserRepository
will contain functions like getFirstName(String userId)
, getLastName(String userId)
etc. When calling these functions, use the AuthManager
to get the required userId
parameter.
Looking for feedback and suggestions.