Delay in finding facebook cookie using JS + Python

Using a combination of GAE, Python, and JS, I successfully made an application connecting to the facebooks API. Only one catch: in my application - the first thing I will check is if there is a facebook cookie:

cookie = facebook.get_user_from_cookie(self.request.cookies, FACEBOOK_APP_ID, FACEBOOK_APP_SECRET) if cookie: {render index.html} else: {render login.html} 

In my handler, I again check the cookie (the same code structure) to prevent people who have cookies from accessing this page. It works the way it was designed.

The only problem is that when the cookie exists, there seems to be some delay in detecting this. So the log goes:

  • cookie not found in index handler, redirect to login handler
  • login-handler draws login-html
  • cookie found in login handler, redirect to index handler
  • index-handler draws index-html

This is clearly visible to end users, the slogan draws, and then, after a second or so, the correct index screen is drawn.

What could be causing this delay? I am wondering if this is caused if a cookie is sent to the server? If so, how to code it?

+4
source share
1 answer

Cookie fbsr_<application_id> will be set only after the user is authenticated on Facebook, redirected back to your application, and the FB.init() API FB.init() method will be executed with cookie: true .

 FB.init({ appId : '<application_id>', status : true, cookie : true, //... 

In other words, a cookie is not set immediately after a user is redirected back to your application.

0
source

All Articles