Skip to content

Commit

Permalink
Merge pull request #25431 from Expensify/tgolen-mapboxtoken-read
Browse files Browse the repository at this point in the history
[No QA] Make sure only the active leader is managing the mapbox token
  • Loading branch information
tgolen authored Aug 18, 2023
2 parents cab5b57 + 66773f5 commit dd2c98b
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/libs/actions/MapboxToken.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import lodashGet from 'lodash/get';
import ONYXKEYS from '../../ONYXKEYS';
import * as API from '../API';
import CONST from '../../CONST';
import * as ActiveClientManager from '../ActiveClientManager';

let authToken;
Onyx.connect({
Expand Down Expand Up @@ -66,6 +67,13 @@ const init = () => {
* @param {String[]} [token.errors]
*/
callback: (token) => {
// Only the leader should be in charge of the mapbox token, or else when you have multiple tabs open, the Onyx connection fires multiple times
// and it sets up duplicate refresh timers. This would be a big waste of tokens.
if (!ActiveClientManager.isClientTheLeader()) {
console.debug('[MapboxToken] This client is not the leader so ignoring onyx callback');
return;
}

// If the user has logged out, don't do anything and ignore changes to the access token
if (!authToken) {
console.debug('[MapboxToken] Ignoring changes to token because user signed out');
Expand All @@ -76,7 +84,7 @@ const init = () => {
// The API sets a token in Onyx with a 30 minute expiration.
if (_.isEmpty(token)) {
console.debug('[MapboxToken] Token does not exist so fetching one');
API.write('GetMapboxAccessToken');
API.read('GetMapboxAccessToken');
isCurrentlyFetchingToken = true;
return;
}
Expand Down

0 comments on commit dd2c98b

Please sign in to comment.