diff --git a/src/providers/auth.tsx b/src/providers/auth.tsx index 6ef9ecf..3821760 100644 --- a/src/providers/auth.tsx +++ b/src/providers/auth.tsx @@ -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{ setToken: React.Dispatch> diff --git a/src/providers/http.tsx b/src/providers/http.tsx index 1e47e0b..b0dd25b 100644 --- a/src/providers/http.tsx +++ b/src/providers/http.tsx @@ -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({} 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(url: string): Promise> { - console.log(defaultOptions()) - return axios.get(url, {...defaultOptions()}); + function get(url: string, spreadOptions?: AxiosRequestConfig): Promise> { + return axios.get(url, {...defaultOptions(), ...spreadOptions}); } function put(