From f062439aa8ad910bf5e15e7c2ad276bcafdc72af Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Thu, 1 Oct 2020 14:27:31 -0700 Subject: [PATCH 1/2] Block requests made without an authToken --- src/lib/API.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/lib/API.js b/src/lib/API.js index cc02825d2124..cda73ac76de5 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,16 @@ 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 = []; + return Promise.resolve(); + } + // Add authToken automatically to all commands const parametersWithAuthToken = {...parameters, ...{authToken}}; From ec290ac83c6671fe2bda5133307bd32fcd7035ab Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Fri, 2 Oct 2020 09:32:37 -0700 Subject: [PATCH 2/2] add redirectToSignIn --- src/lib/API.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib/API.js b/src/lib/API.js index cda73ac76de5..d18bb3bd2558 100644 --- a/src/lib/API.js +++ b/src/lib/API.js @@ -189,6 +189,7 @@ function request(command, parameters, type = 'post') { console.error('A request was made without an authToken', {command, parameters}); reauthenticating = false; networkRequestQueue = []; + redirectToSignIn(); return Promise.resolve(); }