Skip to content

Commit

Permalink
update function
Browse files Browse the repository at this point in the history
  • Loading branch information
pradeepmdk committed Sep 19, 2023
1 parent 5b7f27e commit 6fb66ea
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/libs/actions/MapboxToken.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ const clearToken = () => {
Onyx.set(ONYXKEYS.MAPBOX_ACCESS_TOKEN, null);
};

const fetchToken = () => {
console.debug('[MapboxToken] Token does not exist so fetching one');
API.read('GetMapboxAccessToken');
isCurrentlyFetchingToken = true;
};

const init = () => {
if (connectionIDForToken) {
console.debug('[MapboxToken] init() is already listening to Onyx so returning early');
Expand Down Expand Up @@ -82,9 +88,7 @@ const init = () => {
// If the token is falsy or an empty object, the token needs to be retrieved from the API.
// 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.read('GetMapboxAccessToken');
isCurrentlyFetchingToken = true;
fetchToken();
return;
}

Expand Down Expand Up @@ -127,10 +131,7 @@ const init = () => {
// trigger the fetch of a new one
if (network && network.isOffline && val && !val.isOffline) {
if (_.isEmpty(currentToken)) {
console.debug('[MapboxToken] Token does not exist so fetching one');
// eslint-disable-next-line rulesdir/no-multiple-api-calls
API.read('GetMapboxAccessToken');
isCurrentlyFetchingToken = true;
fetchToken();
} else if (!isCurrentlyFetchingToken && hasTokenExpired()) {
console.debug('[MapboxToken] Token is expired after network came online');
clearToken();
Expand Down

0 comments on commit 6fb66ea

Please sign in to comment.