diff --git a/src/lib/API.js b/src/lib/API.js index cc02825d2124..d18bb3bd2558 100644 --- a/src/lib/API.js +++ b/src/lib/API.js @@ -53,7 +53,9 @@ Ion.connect({ // returns from the background. So, if we are returning from the background // and we are online we should trigger our reconnection callbacks. Activity.registerOnAppBecameActiveCallback(() => { - if (isOffline) { + // If we know we are offline and we have no authToken then there's + // no reason to trigger the reconnection callbacks as they will fail. + if (isOffline || !authToken) { return; } @@ -180,6 +182,17 @@ function request(command, parameters, type = 'post') { }); } + // If we end up here with no authToken it means we are trying to make + // an API request before we are signed in. In this case, we should just + // cancel this and all other requests and set reauthenticating to false. + if (!authToken) { + console.error('A request was made without an authToken', {command, parameters}); + reauthenticating = false; + networkRequestQueue = []; + redirectToSignIn(); + return Promise.resolve(); + } + // Add authToken automatically to all commands const parametersWithAuthToken = {...parameters, ...{authToken}};