mirror of
https://github.com/Monadical-SAS/reflector.git
synced 2025-12-20 20:29:06 +00:00
Previously, API calls were being made before the auth token was configured, causing initial 401 errors that would retry with 200 after token setup. Changes: - Add global auth readiness tracking in apiClient - Create useAuthReady hook that checks both session and token state - Update all API hooks to use isAuthReady instead of just session status - Add AuthWrapper component at layout level for consistent loading UX - Show spinner while authentication initializes across all pages This ensures API calls only fire after authentication is fully configured, eliminating the 401/retry pattern and improving user experience.
68 lines
1.2 KiB
TypeScript
68 lines
1.2 KiB
TypeScript
import { GetTranscript } from "../../lib/api-types";
|
|
import { useTranscriptGet } from "../../lib/api-hooks";
|
|
|
|
type ErrorTranscript = {
|
|
error: Error;
|
|
loading: false;
|
|
response: null;
|
|
reload: () => void;
|
|
};
|
|
|
|
type LoadingTranscript = {
|
|
response: null;
|
|
loading: true;
|
|
error: false;
|
|
reload: () => void;
|
|
};
|
|
|
|
type SuccessTranscript = {
|
|
response: GetTranscript;
|
|
loading: false;
|
|
error: null;
|
|
reload: () => void;
|
|
};
|
|
|
|
const useTranscript = (
|
|
id: string | null,
|
|
): ErrorTranscript | LoadingTranscript | SuccessTranscript => {
|
|
const { data, isLoading, error, refetch } = useTranscriptGet(id);
|
|
|
|
// Map to the expected return format
|
|
if (isLoading) {
|
|
return {
|
|
response: null,
|
|
loading: true,
|
|
error: false,
|
|
reload: refetch,
|
|
};
|
|
}
|
|
|
|
if (error) {
|
|
return {
|
|
error: error as Error,
|
|
loading: false,
|
|
response: null,
|
|
reload: refetch,
|
|
};
|
|
}
|
|
|
|
// Check if data is undefined or null
|
|
if (!data) {
|
|
return {
|
|
response: null,
|
|
loading: true,
|
|
error: false,
|
|
reload: refetch,
|
|
};
|
|
}
|
|
|
|
return {
|
|
response: data as GetTranscript,
|
|
loading: false,
|
|
error: null,
|
|
reload: refetch,
|
|
};
|
|
};
|
|
|
|
export default useTranscript;
|