title: Understanding the Session Manager and Zend\Authenticate in ZF2
body: <p>In the login action I'm having the following code:</p>
  
  <pre><code>public function login($sEmail, $sEncryptedPassword, $bIsClear = true)
  {
      $manager = $this-&gt;getServiceLocator()-&gt;get('session_manager');
      $manager-&gt;start();
  
      Container::setDefaultManager($manager);
  
      $this-&gt;auth = new AuthenticationService();
      $this-&gt;auth-&gt;setStorage(new Session('FSP'));
  
      $dbAdapter = $this-&gt;getServiceLocator()-&gt;get('Zend\Db\Adapter\Adapter');
      $this-&gt;authAdapter = new AuthAdapter(
          $dbAdapter,
          'fsp_user',
          'email',
          'password'
      );
  
     $this-&gt;authAdapter
          -&gt;setIdentity($sEmail)
          -&gt;setCredential($sEncryptedPassword);
  
     $authAuthenticate = $this-&gt;auth-&gt;authenticate($this-&gt;authAdapter);
  
     if ($authAuthenticate-&gt;isValid()) {
  
  
          $user = $this-&gt;authAdapter-&gt;getResultRowObject();
  
  
  
          $storage = $this-&gt;auth-&gt;getStorage();
  
          $storage-&gt;write(
              array(
                  'email' =&gt; $user-&gt;email,
                  'first_name' =&gt; $user-&gt;first_name,
                  'last_name' =&gt; $user-&gt;last_name,
                  'id' =&gt; $user-&gt;id
              )
          );
     }
  </code></pre>
  
  <p>I have two problems with this code:
  1) I'm saving the session in the database, and the session SaveHandler is configured in a service manager. I don't know if once I'm using Zend\Authenticate I should use the session manager too. In the documentation is saying that </p>
  
  <blockquote>
    <p>"Unless specified otherwise, Zend\Authentication\AuthenticationService
    uses a storage class named Zend\Authentication\Storage\Session, which,
    in turn, uses Zend\Session."</p>
  </blockquote>
  
  <p>So my first question is: can I configure the sessionHandler using just Zend\Authenticate or do I have to use the session manager?</p>
  
  <p>2)I can't figured out how session storage is working in ZF. After login, the session data is not persisted in the DB. If I'm doing some debugging I get the following data:</p>
  
  <pre><code>    $session = new Container("FSP");
      //this returns the session data 
      var_dump($session-&gt;getIterator());
  
  
    //this returns empty
      var_dump($this-&gt;auth-&gt;getStorage());
  
  
    //this returns null, but I do have a FSP named cookie with an Id, showing in Chrome's developer tool
      $cookie = $this-&gt;getServiceLocator()-&gt;get('request')-&gt;getHeaders()-&gt;get('cookie');
      $sessionId = $cookie-&gt;FSP;
      var_dump($sessionId);
  </code></pre>
  
  <p>However, if I'm doing a refresh on the login (the login action is run again) the data from the previous session is wrote in the DB and not the data from the current one. 
  So the second question is, why the session data is not persisted in the database at login and at what step in the session instantiation process is the cookie with the session ID created? </p>