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

View file

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