mirror of
https://github.com/Monadical-SAS/reflector.git
synced 2025-12-21 04:39:06 +00:00
refactor: migrate from @hey-api/openapi-ts to openapi-react-query
- 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
This commit is contained in:
33
www/app/lib/ApiAuthProvider.tsx
Normal file
33
www/app/lib/ApiAuthProvider.tsx
Normal file
@@ -0,0 +1,33 @@
|
||||
"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}</>;
|
||||
}
|
||||
Reference in New Issue
Block a user