Skip to content
This repository was archived by the owner on May 13, 2024. It is now read-only.

Commit f2792c3

Browse files
author
Akanksh Saxena
authored
Merge pull request #432 from aziiee/fix_session_timeout
fix(session): Add buffer for token refresh
2 parents aa46634 + de985df commit f2792c3

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

app/application/authenticator.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ import Ember from "ember";
1010
import BaseAuthenticator from "ember-simple-auth/authenticators/base";
1111
import { Promise } from "rsvp";
1212

13+
/*
14+
* If we don't have this buffer, the refresh is triggered too close to token's
15+
* expiration time or even after it's expired, which can result into unexpected
16+
* session invalidation.
17+
*/
18+
const TIME_BUFFER = 3 * 60000; // 3 Minutes
19+
1320
/**
1421
* The application authorizer
1522
*
@@ -191,7 +198,7 @@ const ApplicationAuthenticator = BaseAuthenticator.extend({
191198
*/
192199
_scheduleTokenRefresh(exp, token) {
193200
const now = new Date().getTime();
194-
const wait = exp - now;
201+
const wait = exp - now - TIME_BUFFER;
195202

196203
cancel(this._refreshTokenTimeout);
197204

0 commit comments

Comments
 (0)