Skip to content

Commit

Permalink
Merge branch 'session-refresh-check' into jspm
Browse files Browse the repository at this point in the history
  • Loading branch information
peteruithoven committed May 18, 2017
2 parents 50138ea + 1870be3 commit 16fa613
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,16 +248,16 @@ class Superlogin extends EventEmitter2 {
if (!this._session || !this._session.user_id) {
return Promise.reject();
}
const issued = this._session.issued;
const refreshed = this._session.refreshed;
const expires = this._session.expires;
const threshold = isNaN(this._config.refreshThreshold) ? 0.5 : this._config.refreshThreshold;
const duration = expires - issued;
const duration = expires - refreshed;
let timeDiff = this._session.serverTimeDiff || 0;
if (Math.abs(timeDiff) < 5000) {
timeDiff = 0;
}
const estimatedServerTime = Date.now() + timeDiff;
const elapsed = estimatedServerTime - issued;
const elapsed = estimatedServerTime - refreshed;
const ratio = elapsed / duration;
if (ratio > threshold) {
debug.info('Refreshing session');
Expand Down

0 comments on commit 16fa613

Please sign in to comment.