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 1 commit
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 ONYXKEYS from '../../ONYXKEYS';
import * as API from '../API';
import CONST from '../../CONST';
import {isClientTheLeader} from '../ActiveClientManager';

Check failure on line 9 in src/libs/actions/MapboxToken.js

View workflow job for this annotation

GitHub Actions / lint

Do not import individual exports from local modules. Prefer 'import * as' syntax

let authToken;
Onyx.connect({
Expand Down Expand Up @@ -66,6 +67,13 @@
* @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 (!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 @@
// 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