Skip to content

Commit ab7103b

Browse files
committed
check if Onyx is ready when app is authenticating
fix setTimeout
1 parent b7e9054 commit ab7103b

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/libs/API.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,17 @@ Onyx.connect({
1717
callback: val => credentials = val,
1818
});
1919

20+
let isOnyxReady = false;
2021
let authToken;
2122
Onyx.connect({
2223
key: ONYXKEYS.SESSION,
23-
callback: val => authToken = val ? val.authToken : null,
24+
callback: val => setTimeout(() => { // TODO: remove setTimeout
25+
// callback: (val) => {
26+
authToken = val ? val.authToken : null;
27+
isOnyxReady = true;
28+
29+
// },
30+
}, 1000),
2431
});
2532

2633
/**
@@ -80,7 +87,14 @@ function addDefaultValuesToParameters(command, parameters) {
8087
}
8188

8289
// Tie into the network layer to add auth token to the parameters of all requests
83-
Network.registerParameterEnhancer(addDefaultValuesToParameters);
90+
Network.registerParameterEnhancer((command, parameters) => {
91+
if (isOnyxReady) {
92+
return addDefaultValuesToParameters(command, parameters);
93+
}
94+
95+
// TODO: log this to the server
96+
console.debug(`Onyx is not ready in Network.registerParameterEnhancer with command '${command}'`);
97+
});
8498

8599
/**
86100
* @throws {Error} If the "parameters" object has a null or undefined value for any of the given parameterNames

0 commit comments

Comments
 (0)