title: Symfony Login Session data
body: <p>I followed this Tutorial <a href="https://symfony.com/doc/current/security/form_login_setup.html" rel="nofollow noreferrer">https://symfony.com/doc/current/security/form_login_setup.html</a> and I am using the newest Version (4.2.x) but it seems the app is never setting the session value descriped here:</p>
  
  <p><a href="https://symfony.com/doc/current/security/form_login_setup.html#redirecting-to-the-last-accessed-page-with-targetpathtrait" rel="nofollow noreferrer">https://symfony.com/doc/current/security/form_login_setup.html#redirecting-to-the-last-accessed-page-with-targetpathtrait</a></p>
  
  <p>Where and how do I set this? In the documentation it says it will be set automatically, but when I check the session in the debug console - there is nothing like this. The user/admin will now only be redirected to the set paths and never to the requested pages (e.g. somecontroller/action/id)</p>
  
  <p><strong>security.yaml</strong></p>
  
  <pre><code>    firewalls:
      dev:
          pattern: ^/(_(profiler|wdt)|css|images|js)/
          security: false
      main:
          anonymous: true
          guard:
              authenticators:
                  - App\Security\LoginFormAuthenticator
  
          logout:
              path:   app_logout
              target: /
          remember_me:
              secret:   '%kernel.secret%'
              lifetime: 604800 # 1 week in seconds
              path:     /
              secure: true
              name: REMEMBERUSER
          form_login:
              use_referer: true
  </code></pre>
  
  <p><strong>LoginFormAuthentificator.php</strong></p>
  
  <pre><code>    public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey)
  {
      if ($targetPath = $this-&gt;getTargetPath($request-&gt;getSession(), $providerKey)) {
          return new RedirectResponse($targetPath);
      }
  
      if ($this-&gt;security-&gt;isGranted('ROLE_ADMIN')) {
          $path = 'adresses_index';
      } elseif ($this-&gt;security-&gt;isGranted('ROLE_USER')) {
          $path = 'users_profile';
      }
  
      return new RedirectResponse($this-&gt;router-&gt;generate($path));
  }
  </code></pre>
  
  <p>Also I tried it by setting the providerkey hardcoded to <strong>main</strong> and set an hidden input field with _target_path in the login form. Both lead not to the user experience of opening a link which is restricted and after login redirecting the user to that path.</p>
  
  <p>dumping </p>
  
  <blockquote>
    <p>$this->getTargetPath($request->getSession(), $providerKey)</p>
  </blockquote>
  
  <p>returnes <strong>null</strong>.</p>