title: Symfony - Always LOGGED OUT when i go to /login
body: <p>My problem is very simple and I am on this since this morning..</p>
  <p>When I go to /login, i am directly disconnected, i switch to anonymous status on symfony 5.</p>
  <p>This is my login controller :</p>
  <pre><code>/**
   * @Route(&quot;/login&quot;, name=&quot;app_login&quot;)
   * @param AuthenticationUtils $authenticationUtils
   * @return Response
   */
  public function login(AuthenticationUtils $authenticationUtils): Response
  {
       if ($this-&gt;getUser()) {
           return $this-&gt;redirectToRoute('index');
       }
  
      // 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]);
  }
  </code></pre>
  <p>Before I come in my condition (if.. this-&gt;getUser()), I am already disconnected.</p>
  <p>This is my log out controller :</p>
  <pre><code>/**
   * @Route(&quot;/logout&quot;, name=&quot;app_logout&quot;)
   */
  public function logout()
  {
      // controller can be blank: it will never be executed!
      throw new \Exception('Don\'t forget to activate logout in security.yaml');
  }
  </code></pre>
  <p>and the security.yaml :</p>
  <pre><code>security:
  encoders:
      App\Entity\User:
          algorithm: bcrypt
  # https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
  providers:
      users_in_memory: { memory: null }
      app_user_provider:
          entity:
              class: App\Entity\User
              property: email
  firewalls:
      dev:
          pattern: ^/(_(profiler|wdt)|css|images|js)/
          security: false
      main:
          anonymous: lazy
          provider: users_in_memory
          guard:
              authenticators:
                  - App\Security\SecureAuthentication
          logout:
              path: app_logout
              # where to redirect after logout
              target: index
  
          # 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>thanks a lot and have a good day</p>