mirror of
https://github.com/status-im/realm-js.git
synced 2025-01-11 14:54:33 +00:00
Add lower bound when refreshing tokens. (#2116)
This commit is contained in:
parent
f676724fde
commit
747709df02
16
CHANGELOG.md
16
CHANGELOG.md
@ -15,6 +15,22 @@ x.x.x Release notes (yyyy-MM-dd)
|
||||
### Internal
|
||||
* None.
|
||||
|
||||
x.x.x Release notes (yyyy-MM-dd)
|
||||
=============================================================
|
||||
### Enhancements
|
||||
* None.
|
||||
|
||||
### Fixed
|
||||
* Tokens are refreshed ahead of time. If the lifetime of the token is lower than the threshold for refreshing it will cause the client to continously refresh, spamming the server with refresh requests. A lower bound of 10 seconds has been introduced. ([#2115](https://github.com/realm/realm-js/issues/2115), since v1.0.2)
|
||||
|
||||
### Compatibility
|
||||
* Realm Object Server: 3.11.0 or later.
|
||||
* APIs are backwards compatible with all previous release of realm in the 2.x.y series.
|
||||
* File format: Generates Realms with format v9 (Reads and upgrades all previous formats)
|
||||
|
||||
### Internal
|
||||
* None.
|
||||
|
||||
2.19.1 Release notes (2018-11-15)
|
||||
=============================================================
|
||||
### Enhancements
|
||||
|
@ -26,8 +26,9 @@ const require_method = require;
|
||||
const URL = require('url-parse');
|
||||
|
||||
const refreshTimers = {};
|
||||
const retryInterval = 5 * 1000;
|
||||
const refreshBuffer = 20 * 1000;
|
||||
const retryInterval = 5 * 1000; // Amount of time between retrying authentication requests, if the first request failed.
|
||||
const refreshBuffer = 20 * 1000; // A "safe" amount of time before a token expires that allow us to refresh it.
|
||||
const refreshLowerBound = 10 * 1000; // Lower bound for refreshing tokens.
|
||||
|
||||
function node_require(module) {
|
||||
return require_method(module);
|
||||
@ -119,7 +120,7 @@ function scheduleAccessTokenRefresh(user, localRealmPath, realmUrl, expirationDa
|
||||
// We assume that access tokens have ~ the same expiration time, so if someone already
|
||||
// scheduled a refresh, it's likely to complete before the one we would have scheduled
|
||||
if (!userTimers[localRealmPath]) {
|
||||
const timeout = expirationDate - Date.now() - refreshBuffer;
|
||||
const timeout = Math.max(expirationDate - Date.now() - refreshBuffer, refreshLowerBound);
|
||||
userTimers[localRealmPath] = setTimeout(() => {
|
||||
delete userTimers[localRealmPath];
|
||||
refreshAccessToken(user, localRealmPath, realmUrl);
|
||||
|
Loading…
x
Reference in New Issue
Block a user