-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Retry requests if storage (auth + credentials) is not ready #6183
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
Changes from all commits
bb59f93
bb69c23
8552b0a
79bcfb6
2bbddeb
9c2ff14
56b0bb8
ab15fa6
acfc39a
d0f9acc
480b81c
b4b694e
78da9e4
3713f70
9ac5627
a67d885
60df933
0b2f305
1e0a163
ec2ee08
62ef020
1226f64
623c8a3
ea99e0b
63d35a8
b8a580b
1f23139
61f2df0
c6fb00f
7f22cab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| /* eslint-disable rulesdir/prefer-onyx-connect-in-libs */ | ||
| import Onyx, {withOnyx} from 'react-native-onyx'; | ||
|
|
||
| let connectCallbackDelay = 0; | ||
| function addDelayToConnectCallback(delay) { | ||
| connectCallbackDelay = delay; | ||
| } | ||
|
|
||
| export default { | ||
| ...Onyx, | ||
| connect: mapping => Onyx.connect({ | ||
| ...mapping, | ||
| callback: (...params) => { | ||
| if (connectCallbackDelay > 0) { | ||
| setTimeout(() => { | ||
| mapping.callback(...params); | ||
| }, connectCallbackDelay); | ||
| } else { | ||
| mapping.callback(...params); | ||
| } | ||
| }, | ||
| }), | ||
| addDelayToConnectCallback, | ||
| }; | ||
| export {withOnyx}; | ||
| /* eslint-enable rulesdir/prefer-onyx-connect-in-libs */ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,25 +6,40 @@ import CONFIG from '../CONFIG'; | |
| import ONYXKEYS from '../ONYXKEYS'; | ||
| // eslint-disable-next-line import/no-cycle | ||
| import redirectToSignIn from './actions/SignInRedirect'; | ||
| import * as Network from './Network'; | ||
| import isViaExpensifyCashNative from './isViaExpensifyCashNative'; | ||
|
|
||
| // eslint-disable-next-line import/no-cycle | ||
| import * as Network from './Network'; | ||
| // eslint-disable-next-line import/no-cycle | ||
| import LogUtil from './Log'; | ||
| // eslint-disable-next-line import/no-cycle | ||
| import * as Session from './actions/Session'; | ||
|
|
||
| let isAuthenticating; | ||
| let credentials; | ||
| let authToken; | ||
|
|
||
| function checkRequiredDataAndSetNetworkReady() { | ||
| if (_.isUndefined(authToken) || _.isUndefined(credentials)) { | ||
| return; | ||
| } | ||
|
|
||
| Network.setIsReady(true); | ||
| } | ||
|
|
||
| Onyx.connect({ | ||
| key: ONYXKEYS.CREDENTIALS, | ||
| callback: val => credentials = val, | ||
| callback: (val) => { | ||
| credentials = val || null; | ||
| checkRequiredDataAndSetNetworkReady(); | ||
| }, | ||
| }); | ||
|
|
||
| let authToken; | ||
| Onyx.connect({ | ||
| key: ONYXKEYS.SESSION, | ||
| callback: val => authToken = val ? val.authToken : null, | ||
| callback: (val) => { | ||
| authToken = lodashGet(val, 'authToken', null); | ||
| checkRequiredDataAndSetNetworkReady(); | ||
| }, | ||
| }); | ||
|
|
||
| /** | ||
|
|
@@ -59,18 +74,6 @@ function addDefaultValuesToParameters(command, parameters) { | |
| const finalParameters = {...parameters}; | ||
|
|
||
| if (isAuthTokenRequired(command) && !parameters.authToken) { | ||
| // 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 cancel the current request by pausing the queue and clearing the remaining requests. | ||
| if (!authToken) { | ||
| redirectToSignIn(); | ||
|
marcaaron marked this conversation as resolved.
|
||
|
|
||
| LogUtil.info('A request was made without an authToken', false, {command, parameters}); | ||
| Network.pauseRequestQueue(); | ||
| Network.clearRequestQueue(); | ||
| Network.unpauseRequestQueue(); | ||
| return; | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nickmurray47 comment makes me wonder if we should add a test for this. But maybe it is already covered.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess the manual test would just be...
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like adding both of those! |
||
|
|
||
| finalParameters.authToken = authToken; | ||
| } | ||
|
|
||
|
|
@@ -197,7 +200,7 @@ Network.registerErrorHandler((queuedRequest, error) => { | |
|
|
||
| /** | ||
| * @param {Object} parameters | ||
| * @param {String} [parameters.useExpensifyLogin] | ||
| * @param {Boolean} [parameters.useExpensifyLogin] | ||
| * @param {String} parameters.partnerName | ||
| * @param {String} parameters.partnerPassword | ||
| * @param {String} parameters.partnerUserID | ||
|
|
@@ -448,6 +451,7 @@ function Get(parameters, shouldUseSecure = false) { | |
| /** | ||
| * @param {Object} parameters | ||
| * @param {String} parameters.email | ||
| * @param {Boolean} parameters.forceNetworkRequest | ||
| * @returns {Promise} | ||
| */ | ||
| function GetAccountStatus(parameters) { | ||
|
|
@@ -1015,14 +1019,13 @@ function DeleteBankAccount(parameters) { | |
|
|
||
| /** | ||
| * @param {Object} parameters | ||
| * @param {String[]} data | ||
| * @returns {Promise} | ||
| */ | ||
| function Mobile_GetConstants(parameters) { | ||
| const commandName = 'Mobile_GetConstants'; | ||
| requireParameters(['data'], parameters, commandName); | ||
|
|
||
| // Stringinfy the parameters object as we cannot send an object via FormData | ||
| // Stringify the parameters object as we cannot send an object via FormData | ||
| const finalParameters = parameters; | ||
| finalParameters.data = JSON.stringify(parameters.data); | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.