✨ (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:
cristhianzl 2024-04-08 21:42:34 -03:00
commit afff3228c7

View file

@ -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(() => {