Answer the question
In order to leave comments, you need to log in
How to reduce component coupling?
I am designing an application. There are the following concepts:
- components
- modules
- core
I have the following dilemma:
There is an auth component, jwt and a User module. The fact is that I need to authenticate the user by login and password (the auth component answers), give the user a jwt token (while making all the necessary entries in the database, the jwt component), and actually use the User entity and the repository from the User module.
It turns out that each of the components must know about the User module (more precisely, about the User entity and the repository).
However it would be desirable to reduce all this business with connectivity to a minimum.
For example, what the authentication component will look like:
public function attempt(CredentialsDTO $credentials)
{
$username = $credentials->getUsername();
$password = $credentials->getPassword();
if ($passwordHash = $this->userRepository->findPasswordHashByUsername($username)) {
if ($this->hasher->check($password, $passwordHash)) {
$user = $this->userRepository->findByUsername($username);
// TODO: сгенерировать jwt токен
}
}
return false;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question