Skip to content

Commit 54cb877

Browse files
committed
check if Onyx is ready when app is authenticating
fix setTimeout
1 parent dcfde19 commit 54cb877

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
@@ -14,10 +14,17 @@ Onyx.connect({
1414
callback: val => credentials = val,
1515
});
1616

17+
let isOnyxReady = false;
1718
let authToken;
1819
Onyx.connect({
1920
key: ONYXKEYS.SESSION,
20-
callback: val => authToken = val ? val.authToken : null,
21+
callback: val => setTimeout(() => { // TODO: remove setTimeout
22+
// callback: (val) => {
23+
authToken = val ? val.authToken : null;
24+
isOnyxReady = true;
25+
26+
// },
27+
}, 1000),
2128
});
2229

2330
/**
@@ -77,7 +84,14 @@ function addDefaultValuesToParameters(command, parameters) {
7784
}
7885

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

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

0 commit comments

Comments
 (0)