refactor(frontend): optimise auth process

- Stops frontend trying to make calls that require auth before auth has occured
- Stops frontend making calls that aren't necessary before auth has occured
- Implements state machine to better handle auth phases
This commit is contained in:
tigattack
2025-09-25 19:39:52 +01:00
parent ba087eb23e
commit 5c66887732
5 changed files with 90 additions and 26 deletions

View File

@@ -241,6 +241,14 @@ const Layout = ({ children }) => {
// Fetch GitHub stars count
const fetchGitHubStars = useCallback(async () => {
// Skip if already fetched recently
const lastFetch = localStorage.getItem("githubStarsFetchTime");
const now = Date.now();
if (lastFetch && now - parseInt(lastFetch, 15) < 600000) {
// 15 minute cache
return;
}
try {
const response = await fetch(
"https://api.github.com/repos/9technologygroup/patchmon.net",
@@ -248,6 +256,7 @@ const Layout = ({ children }) => {
if (response.ok) {
const data = await response.json();
setGithubStars(data.stargazers_count);
localStorage.setItem("githubStarsFetchTime", now.toString());
}
} catch (error) {
console.error("Failed to fetch GitHub stars:", error);