mirror of
https://github.com/StanGirard/quivr.git
synced 2024-12-25 04:12:44 +03:00
d9a72b368a
Issue: https://github.com/StanGirard/quivr/issues/1683 Demo: https://github.com/StanGirard/quivr/assets/63923024/67cf2a0f-4cfe-420c-9181-baffaa584c78 https://github.com/StanGirard/quivr/assets/63923024/eee57598-1520-4c11-bd64-887869878f46
30 lines
764 B
TypeScript
30 lines
764 B
TypeScript
import axios, { AxiosError, AxiosInstance } from "axios";
|
|
|
|
import { useSupabase } from "@/lib/context/SupabaseProvider";
|
|
|
|
import { DEFAULT_BACKEND_URL } from "../config/CONSTANTS";
|
|
|
|
const axiosInstance = axios.create({
|
|
baseURL: `${process.env.NEXT_PUBLIC_BACKEND_URL ?? DEFAULT_BACKEND_URL}`,
|
|
});
|
|
|
|
export const useAxios = (): { axiosInstance: AxiosInstance } => {
|
|
const { session } = useSupabase();
|
|
axiosInstance.interceptors.request.clear();
|
|
axiosInstance.interceptors.request.use(
|
|
(config) => {
|
|
config.headers["Authorization"] = `Bearer ${session?.access_token ?? ""}`;
|
|
|
|
return config;
|
|
},
|
|
(error: AxiosError) => {
|
|
console.error({ error });
|
|
void Promise.reject(error);
|
|
}
|
|
);
|
|
|
|
return {
|
|
axiosInstance,
|
|
};
|
|
};
|