Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

auto refresh session every 20 minutes

Summary:
adds logic to setup a timer to ping login_status every 20 minutes. we
only do this if getLoginStatus() was invoked at least once. this ensures
that applications that do not want to fetch sessions in JS will not
get this timer. if the session will not expire, we do not setup a timer
either.

Test Plan:
For testing, I reduced the timeout from 20 minutes to 30 seconds. Then
tested that the timer is setup on page load, if a session is found, and
on login, if a session is returned.

DiffCamp Revision: 120550
Reviewed By: wzhu
CC: platform-diffs@lists, lshepard, brent, mattwkelly, wzhu, selekman
Revert Plan:
OK
  • Loading branch information...
commit 5b15174c7c9b9ea669499804d4a4c7d80771b036 1 parent 1800a4c
Naitik Shah authored June 04, 2010

Showing 1 changed file with 16 additions and 0 deletions. Show diff stats Hide diff stats

  1. 16  src/core/auth.js
16  src/core/auth.js
@@ -333,6 +333,22 @@ FB.provide('Auth', {
333 333
       FB.Event.fire('auth.sessionChange', response);
334 334
     }
335 335
 
  336
+    // re-setup a timer to refresh the session if needed. we only do this if
  337
+    // FB.Auth._loadState exists, indicating that the application relies on the
  338
+    // JS to get and refresh session information (vs managing it themselves).
  339
+    if (FB.Auth._refreshTimer) {
  340
+      window.clearTimeout(FB.Auth._refreshTimer);
  341
+      delete FB.Auth._refreshTimer;
  342
+    }
  343
+    if (FB.Auth._loadState && session && session.expires) {
  344
+      // refresh every 20 minutes. we don't rely on the expires time because
  345
+      // then we would also need to rely on the local time available in JS
  346
+      // which is often incorrect.
  347
+      FB.Auth._refreshTimer = window.setTimeout(function() {
  348
+        FB.getLoginStatus(null, true); // force refresh
  349
+      }, 1200000); // 20 minutes
  350
+    }
  351
+
336 352
     return response;
337 353
   },
338 354
 

0 notes on commit 5b15174

Please sign in to comment.
Something went wrong with that request. Please try again.