title: Symfony 5 onAuthenticationSuccess not being triggered
body: <p>I'm using <strong>Symfony 5.3.1</strong> and I'm implementing the default authentication system.</p>
  <ol>
  <li>php bin/console make:user</li>
  <li>php bin/console doctrine:schema:update --force</li>
  <li>php bin/console make:auth</li>
  <li>php bin/console make:registration</li>
  </ol>
  <p>When I register a new user using the automatically created register template is perfectly working and the user is added to my MySQL database.</p>
  <p>But, when I log in a user in the /login template nothing happens. No redirect. No error.</p>
  <p>What I expect is onAuthenticationSuccess being called from /Security/LoginAuthenticator.</p>
  <p><strong>This is my /Security/LoginAuthenticator</strong></p>
  <pre><code>&lt;?php
  
  namespace App\Security;
  
  use Symfony\Component\HttpFoundation\RedirectResponse;
  use Symfony\Component\HttpFoundation\Request;
  use Symfony\Component\HttpFoundation\Response;
  use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  use Symfony\Component\Security\Core\Security;
  use Symfony\Component\Security\Http\Authenticator\AbstractLoginFormAuthenticator;
  use Symfony\Component\Security\Http\Authenticator\Passport\Badge\CsrfTokenBadge;
  use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge;
  use Symfony\Component\Security\Http\Authenticator\Passport\Credentials\PasswordCredentials;
  use Symfony\Component\Security\Http\Authenticator\Passport\Passport;
  use Symfony\Component\Security\Http\Authenticator\Passport\PassportInterface;
  use Symfony\Component\Security\Http\Util\TargetPathTrait;
  
  class LoginAuthenticator extends AbstractLoginFormAuthenticator
  {
      use TargetPathTrait;
  
      public const LOGIN_ROUTE = 'app_login';
  
      private UrlGeneratorInterface $urlGenerator;
  
      public function __construct(UrlGeneratorInterface $urlGenerator)
      {
          $this-&gt;urlGenerator = $urlGenerator;
      }
  
      public function authenticate(Request $request): PassportInterface
      {
          $username = $request-&gt;request-&gt;get('username', '');
  
          $request-&gt;getSession()-&gt;set(Security::LAST_USERNAME, $username);
  
          return new Passport(
              new UserBadge($username),
              new PasswordCredentials($request-&gt;request-&gt;get('password', '')),
              [
                  new CsrfTokenBadge('authenticate', $request-&gt;get('_csrf_token')),
              ]
          );
      }
  
      public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $firewallName): ?Response
      {
          
          if ($targetPath = $this-&gt;getTargetPath($request-&gt;getSession(), $firewallName)) {
              return new RedirectResponse($targetPath);
          }
          
          // For example:
          //return new RedirectResponse($this-&gt;urlGenerator-&gt;generate('some_route'));
          throw new \Exception('TODO: provide a valid redirect inside '.__FILE__);
      }
  
      protected function getLoginUrl(Request $request): string
      {
          return $this-&gt;urlGenerator-&gt;generate(self::LOGIN_ROUTE);
      }
  }
  </code></pre>
  <p><strong>This is my security.yaml:</strong></p>
  <pre><code>security:
      encoders:
          App\Entity\User:
              algorithm: auto
  
      # https://symfony.com/doc/current/security/experimental_authenticators.html
      enable_authenticator_manager: true
      # https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
      providers:
          # used to reload user from session &amp; other features (e.g. switch_user)
          app_user_provider:
              entity:
                  class: App\Entity\User
                  property: username
      firewalls:
          dev:
              pattern: ^/(_(profiler|wdt)|css|images|js)/
              security: false
          main:
              lazy: true
              provider: app_user_provider
              logout:
                  path: app_logout
                  # where to redirect after logout
                  target: link.index
              custom_authenticator: App\Security\LoginAuthenticator
  
              # activate different ways to authenticate
              # https://symfony.com/doc/current/security.html#firewalls-authentication
  
              # https://symfony.com/doc/current/security/impersonating_user.html
              # switch_user: true
  
      # Easy way to control access for large sections of your site
      # Note: Only the *first* access control that matches will be used
      access_control:
          # - { path: ^/admin, roles: ROLE_ADMIN }
          # - { path: ^/profile, roles: ROLE_USER }
  </code></pre>
  <p><strong>And finally this is my SecurityController:</strong></p>
  <pre><code>&lt;?php
  
  namespace App\Controller;
  
  use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  use Symfony\Component\HttpFoundation\Response;
  use Symfony\Component\Routing\Annotation\Route;
  use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  
  class SecurityController extends AbstractController
  {
      /**
       * @Route(&quot;/login&quot;, priority=10, name=&quot;app_login&quot;)
       */
      public function login(AuthenticationUtils $authenticationUtils): Response
      {
          // if ($this-&gt;getUser()) {
          //     return $this-&gt;redirectToRoute('target_path');
          // }
  
          // get the login error if there is one
          $error = $authenticationUtils-&gt;getLastAuthenticationError();
          // last username entered by the user
          $lastUsername = $authenticationUtils-&gt;getLastUsername();
  
          return $this-&gt;render('security/login.html.twig', ['last_username' =&gt; $lastUsername, 'error' =&gt; $error]);
      }
  
      /**
       * @Route(&quot;/logout&quot;, priority=12, name=&quot;app_logout&quot;)
       */
      public function logout()
      {
          throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
      }
  }
  </code></pre>
  <p>I have being 2 days looking for a solution and nothing worked. Here is a picture of my login form:</p>
  <p><a href="https://i.stack.imgur.com/QaiGE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QaiGE.png" alt="Login form symfony" /></a></p>
  <p>After clicking Sign in, the page is refreshed and nothing happens.</p>
  <p>Thank you.</p>