Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[No QA] Make sure only the active leader is managing the mapbox token #25431

Merged
merged 3 commits into from
Aug 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading