✨ (App.tsx): refactor code to use async/await syntax for fetching data when the user is authenticated
🐛 (App.tsx): handle errors when fetching data and log them to the console for debugging purposes
This commit is contained in:
parent
452eb224d7
commit
afff3228c7
1 changed files with 15 additions and 12 deletions
|
|
@ -56,18 +56,21 @@ export default function App() {
|
||||||
refreshStars();
|
refreshStars();
|
||||||
refreshVersion();
|
refreshVersion();
|
||||||
|
|
||||||
// If the user is authenticated, fetch the types. This code is important to check if the user is auth because of the execution order of the useEffect hooks.
|
const fetchData = async () => {
|
||||||
if (isAuthenticated === true) {
|
if (isAuthenticated) {
|
||||||
// get data from db
|
try {
|
||||||
getTypes().then(() => {
|
await getTypes();
|
||||||
refreshFlows();
|
refreshFlows();
|
||||||
});
|
const res = await getGlobalVariables();
|
||||||
getGlobalVariables().then((res) => {
|
setGlobalVariables(res);
|
||||||
setGlobalVariables(res);
|
checkHasStore();
|
||||||
});
|
fetchApiData();
|
||||||
checkHasStore();
|
} catch (error) {
|
||||||
fetchApiData();
|
console.error("Failed to fetch data:", error);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
fetchData();
|
||||||
}, [isAuthenticated]);
|
}, [isAuthenticated]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue