Merge pull request #1015 from khoj-ai/features/clean-up-authenticated-data

- De facto, was being assumed everywhere if authenticatedData is null, that it's not logged in. This isn't true because the data can still be loading. Update the hook to send additional states.
- Bonus: Delete model picker code and a slew of unused imports.
This commit is contained in:
sabaimran
2024-12-24 09:51:39 -08:00
committed by GitHub
18 changed files with 204 additions and 349 deletions

View File

@@ -19,13 +19,15 @@ const fetcher = (url: string) =>
.catch((err) => console.warn(err));
export function useAuthenticatedData() {
const { data, error } = useSWR<UserProfile>("/api/v1/user", fetcher, {
const { data, error, isLoading } = useSWR<UserProfile>("/api/v1/user", fetcher, {
revalidateOnFocus: false,
});
if (error || !data || data.detail === "Forbidden") return null;
if (data?.detail === "Forbidden") {
return { data: null, error: "Forbidden", isLoading: false };
}
return data;
return { data, error, isLoading };
}
export interface ModelOptions {