mirror of
https://github.com/Monadical-SAS/reflector.git
synced 2025-12-20 20:29:06 +00:00
- Replace @hey-api/openapi-ts with openapi-typescript and openapi-react-query - Generate TypeScript types from OpenAPI spec - Set up React Query infrastructure with QueryClientProvider - Migrate all API hooks to use React Query patterns - Maintain backward compatibility for existing components - Remove old API infrastructure and dependencies
34 lines
983 B
TypeScript
34 lines
983 B
TypeScript
"use client";
|
|
|
|
import { useEffect, useContext } from "react";
|
|
import { client, configureApiAuth } from "./apiClient";
|
|
import useSessionAccessToken from "./useSessionAccessToken";
|
|
import { DomainContext } from "../domainContext";
|
|
|
|
export function ApiAuthProvider({ children }: { children: React.ReactNode }) {
|
|
const { accessToken } = useSessionAccessToken();
|
|
const { api_url } = useContext(DomainContext);
|
|
|
|
useEffect(() => {
|
|
// Configure base URL
|
|
if (api_url) {
|
|
client.use({
|
|
onRequest({ request }) {
|
|
// Update the base URL for all requests
|
|
const url = new URL(request.url);
|
|
const apiUrl = new URL(api_url);
|
|
url.protocol = apiUrl.protocol;
|
|
url.host = apiUrl.host;
|
|
url.port = apiUrl.port;
|
|
return new Request(url.toString(), request);
|
|
},
|
|
});
|
|
}
|
|
|
|
// Configure authentication
|
|
configureApiAuth(accessToken);
|
|
}, [accessToken, api_url]);
|
|
|
|
return <>{children}</>;
|
|
}
|