code clean

This commit is contained in:
Carter 2024-10-25 15:46:24 -06:00
parent d8151f618a
commit ac7ee6881a
2 changed files with 13 additions and 29 deletions

View file

@ -1,5 +1,5 @@
import { useAuth0 } from "@auth0/auth0-react";
import { PropsWithChildren, useEffect, useState } from "react";
import { PropsWithChildren, useEffect } from "react";
interface Props extends PropsWithChildren<any>{
setToken: React.Dispatch<React.SetStateAction<string | undefined>>

View file

@ -1,10 +1,11 @@
import axios, { AxiosRequestConfig, AxiosResponse } from "axios";
// import { useAuth } from "hooks";
import moment from "moment";
import { createContext, PropsWithChildren, useContext, useEffect, useState } from "react";
import { createContext, PropsWithChildren, useContext } from "react";
// import BillingProvider from "./billing";
// import GitlabProvider from "./gitlab";
import PondProvider from "./pond/pond";
import { useAuth0 } from "@auth0/auth0-react";
// import SecurityProvider from "./security";
// import { useAuth0 } from "@auth0/auth0-react";
@ -32,32 +33,16 @@ export const HTTPContext = createContext<IHTTPContext>({} as IHTTPContext);
export default function HTTPProvider(props: Props) {
const { children, token } = props;
// const { isAuthenticated, /*token,*/ getAccessTokenSilently } = useAuth0();
// const [token, setToken] = useState("");
// useEffect(() => {
// if (isAuthenticated) getAccessTokenSilently().then(t => {
// console.log(t)
// setToken(t)
// }).finally(() => {
// setGotToken(true)
// })
// }, [setToken, isAuthenticated])
const { isAuthenticated } = useAuth0();
const defaultOptions = (demo: boolean = false) => {
// if (demo || !isAuthenticated || !token) {
// console.log("demo: ", demo)
// console.log("Authenticated: ", isAuthenticated)
// console.log("token: ", token)
// return {
// headers: {
// "Content-Type": "application/json"
// }
// };
// }
// console.log("Getting options with Bearer")
// console.log(token)
if (demo || !isAuthenticated || !token) {
return {
headers: {
"Content-Type": "application/json"
}
};
}
const config = {
headers: {
@ -68,9 +53,8 @@ export default function HTTPProvider(props: Props) {
return config;
};
function get<T>(url: string): Promise<AxiosResponse<T>> {
console.log(defaultOptions())
return axios.get(url, {...defaultOptions()});
function get<T>(url: string, spreadOptions?: AxiosRequestConfig): Promise<AxiosResponse<T>> {
return axios.get(url, {...defaultOptions(), ...spreadOptions});
}
function put<T>(