# What does this PR do?


## Test Plan
# What does this PR do?


## Test Plan
# What does this PR do?


## Test Plan
This commit is contained in:
Eric Huang 2025-06-25 20:10:45 -07:00
parent 114946ae88
commit a4d84f7805
22 changed files with 821 additions and 38 deletions

View file

@ -0,0 +1,28 @@
import { useState, useEffect } from "react";
export function useAuthConfig() {
const [isAuthConfigured, setIsAuthConfigured] = useState(true);
const [isChecking, setIsChecking] = useState(true);
useEffect(() => {
const checkAuthConfig = async () => {
try {
const response = await fetch("/api/auth/github/login", {
method: "HEAD",
redirect: "manual",
});
setIsAuthConfigured(response.status !== 404);
} catch (error) {
console.error("Auth config check error:", error);
setIsAuthConfigured(true);
} finally {
setIsChecking(false);
}
};
checkAuthConfig();
}, []);
return { isAuthConfigured, isChecking };
}

View file

@ -2,6 +2,8 @@
import { useState, useCallback, useEffect, useRef } from "react";
import { PaginationStatus, UsePaginationOptions } from "@/lib/types";
import { useRouter } from "next/navigation";
import { AuthenticationError } from "llama-stack-client";
interface PaginationState<T> {
data: T[];
@ -51,6 +53,7 @@ export function usePagination<T>({
error: null,
lastId: null,
});
const router = useRouter();
// Use refs to avoid stale closures
const stateRef = useRef(state);
@ -91,6 +94,12 @@ export function usePagination<T>({
status: "idle",
}));
} catch (err) {
// Handle authentication errors by redirecting to login
if (err instanceof AuthenticationError) {
router.push("/login");
return;
}
const errorMessage = isInitialLoad
? `Failed to load ${errorMessagePrefix}. Please try refreshing the page.`
: `Failed to load more ${errorMessagePrefix}. Please try again.`;
@ -107,7 +116,7 @@ export function usePagination<T>({
}));
}
},
[limit, model, order, fetchFunction, errorMessagePrefix],
[limit, model, order, fetchFunction, errorMessagePrefix, router],
);
/**