self-review-fix

This commit is contained in:
Igor Loskutov
2025-09-02 13:04:43 -04:00
parent bdd899774a
commit 11ed585cea
20 changed files with 124 additions and 127 deletions

View File

@@ -10,13 +10,16 @@ import { isAuthConfigured } from "./apiClient";
* Prevents race conditions where React Query fires requests before the token is set.
*/
export default function useAuthReady() {
const { status, isAuthenticated } = useSessionStatus();
const status = useSessionStatus();
const isAuthenticated = status === "authenticated";
const [authReady, setAuthReady] = useState(false);
useEffect(() => {
let ready_ = false;
// Check if both session is authenticated and token is configured
const checkAuthReady = () => {
const ready = isAuthenticated && isAuthConfigured();
ready_ = ready;
setAuthReady(ready);
};
@@ -27,7 +30,14 @@ export default function useAuthReady() {
const interval = setInterval(checkAuthReady, 100);
// Stop checking after 2 seconds (auth should be ready by then)
const timeout = setTimeout(() => clearInterval(interval), 2000);
const timeout = setTimeout(() => {
if (ready_) {
clearInterval(interval);
return;
} else {
console.warn("Auth not ready after 2 seconds");
}
}, 2000);
return () => {
clearInterval(interval);