abhaybisht2002
04/10/2024, 8:49 AMrp_st
04/10/2024, 8:52 AMabhaybisht2002
04/10/2024, 9:18 AMabhaybisht2002
04/10/2024, 9:18 AMrp_st
04/10/2024, 9:19 AMrp_st
04/10/2024, 9:19 AMrp_st
04/10/2024, 9:19 AMabhaybisht2002
04/10/2024, 9:19 AMabhaybisht2002
04/10/2024, 9:19 AMrp_st
04/10/2024, 9:19 AMrp_st
04/10/2024, 9:19 AMrp_st
04/10/2024, 9:20 AMabhaybisht2002
04/10/2024, 9:20 AMabhaybisht2002
04/10/2024, 9:20 AMrp_st
04/10/2024, 9:21 AMabhaybisht2002
04/10/2024, 9:21 AMrp_st
04/10/2024, 9:21 AMrp_st
04/10/2024, 9:21 AMrp_st
04/10/2024, 9:22 AMabhaybisht2002
04/10/2024, 9:22 AMjsx
function createAxiosInstance() {
const instance = axios.create({
baseURL: process.env.NEXT_PUBLIC_BACKEND_BASE_URL,
withCredentials: true
})
// Request Interceptor
instance.interceptors.request.use((config) => {
return config
}, (error) => {
return Promise.reject(error)
})
// Response Interceptor
instance.interceptors.response.use((response) => {
return response.data
}, (error) => {
return Promise.reject(error)
})
return instance
}
const AxiosContext = createContext<axiosContextType | undefined>(undefined)
export function AxiosProvider({ children }: { children: React.ReactNode }) {
const axiosInstance: AxiosInstance = useMemo(() => createAxiosInstance(), [])
const values: axiosContextType = {
axiosInstance
}
jsx
const getApiKeysByProjectId = async () => {
if (selectedProject && selectedProject.id) {
try {
const response = (await axiosInstance(``)) as ApiKeyType[]
setApiKeys(response)
} catch (err) {
isUnauthorized(err, router)
}
} else {
console.warn("No project selected")
}
}
abhaybisht2002
04/10/2024, 9:22 AMrp_st
04/10/2024, 9:25 AMrp_st
04/10/2024, 9:25 AMrp_st
04/10/2024, 9:25 AMabhaybisht2002
04/10/2024, 9:27 AMrp_st
04/10/2024, 9:28 AM