Answer the question
In order to leave comments, you need to log in
SessionInterface or TokenStorageInterface for authentication?
If the user is authorized, there will be a SessionInterface in the session as an array.
If the user is authorized, and here he will be TokenStorageInterface in the token video.
If you need to check if the user is authenticated, which is better? Why? When to use one or the other?
In my case, I do a check in the EventSubscriber.
Answer the question
In order to leave comments, you need to log in
Information about the authorized user is stored in the security token, in the general case, this is any class that implements TokenInterface . The token itself is stored in token storage , usually the standard TokenStorage . Symfony also provides simplified access to the core security components through the Security class . Thus, if your EventSubscriber needs to check user authentication, this can be done in different ways, depending on what exactly you want to track:
Security
via DI to your service and check if there is a token there and if the user associated with it is authorized:$token = $this->security->getToken();
if ($token instanceof TokenInterface && $token->isAuthenticated()) {
// пользователь прошёл аутентификацию
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question