mirror of
https://github.com/QuivrHQ/quivr.git
synced 2024-12-15 01:21:48 +03:00
9c8e0aa0e4
* 🗑️ remove date input from fetch_user_id_from_credentials * ♻️ refactor backend utils by splitting it into files * 💡 comments for next actions to update /upload * 🚚 move SupabaseProvider tp libs * 🚚 move useAxios to hooks * ♻️ refacto brain routes * 🚨 update lintermfor paths * ✨ new brain context provider * ✨ new brain component in navbar * 🚨 fix linter and async * 🇸🇪 add feature flag for multiple-brains
34 lines
948 B
TypeScript
34 lines
948 B
TypeScript
import axios, { AxiosError, AxiosInstance } from "axios";
|
|
|
|
import { useBrainConfig } from "../context/BrainConfigProvider/hooks/useBrainConfig";
|
|
import { useSupabase } from "../context/SupabaseProvider";
|
|
|
|
const axiosInstance = axios.create({
|
|
baseURL: `${process.env.NEXT_PUBLIC_BACKEND_URL ?? ""}`,
|
|
});
|
|
|
|
export const useAxios = (): { axiosInstance: AxiosInstance } => {
|
|
const { session } = useSupabase();
|
|
const {
|
|
config: { backendUrl, openAiKey },
|
|
} = useBrainConfig();
|
|
axiosInstance.interceptors.request.clear();
|
|
axiosInstance.interceptors.request.use(
|
|
(config) => {
|
|
config.headers["Authorization"] = `Bearer ${session?.access_token ?? ""}`;
|
|
config.headers["Openai-Api-Key"] = openAiKey;
|
|
config.baseURL = backendUrl ?? config.baseURL;
|
|
|
|
return config;
|
|
},
|
|
(error: AxiosError) => {
|
|
console.error({ error });
|
|
void Promise.reject(error);
|
|
}
|
|
);
|
|
|
|
return {
|
|
axiosInstance,
|
|
};
|
|
};
|