title: Facebook: Redirect after login, user session is empty?
body: <p>I am trying to authenticate (login) a user into facebook while requesting some permissions inside an iframe app.</p>
  
  <p>I am using the JS SDK in conjunction with the PHP SDK. So, first I check if the user is logged in and everything is ok using PHP <code>$facebook-&gt;getUser()</code>, when that fails I redirect the user to a page where this JS is run:</p>
  
  <pre><code>FB.getLoginStatus(function(response) {
      if (response.status === "connected") {
          // Ok, go home
      } else {
          FB.login(function(response) {
              if (response.authResponse) {
                  // Ok, go home
              } else {
                  // Cancelled, go home
              }
          }, {scope: '&lt;?php echo implode(',', $this-&gt;permissions); ?&gt;'});
      }
  });
  </code></pre>
  
  <p>This would then create a login dialog asking for permissions. As you can see there are cases for when the user has authenticated/authorized properly and for when the dialog was canceled. In any of those cases I need to do a single thing: redirect back to the root of my application.</p>
  
  <p>So, the dialog pops, the user logs in and then he is redirected back home, where I use PHP to <code>getUser()</code>.</p>
  
  <p>The problem here is that, the first time the user is logged in and redirected, <code>getUser()</code> is always empty, there is no user session. If I refresh the facebook page holding my app's iframe, then there is session and permissions are properly set, indicating that the dialog has done it's job.</p>
  
  <p>Any ideas of why would the first redirect not work?</p>
  
  <p>I found similar issues, but non gives me a specific, working solution.</p>