diff --git a/src/index.js b/src/index.js index 2818ab8..8e66fea 100644 --- a/src/index.js +++ b/src/index.js @@ -4,9 +4,37 @@ import './index.css'; import App from './App'; import 'bootstrap/dist/css/bootstrap.min.css'; +import { ApolloClient, InMemoryCache, createHttpLink } from "@apollo/client"; +import { ApolloProvider } from "@apollo/client/react"; +import { setContext } from "@apollo/client/link/context"; + +const httpLink = createHttpLink({ + uri: "https://api.oemautomation.com:3001", +}); + +const authLink = setContext((_, { headers }) => { + // get the authentication token from local storage if it exists + const token = localStorage.getItem("token"); + // return the headers to the context so httpLink can read them + return { + headers: { + ...headers, + authtoken: "to do here", + authorization: token ? `Bearer ${token}` : "", + }, + }; +}); + +const client = new ApolloClient({ + link: authLink.concat(httpLink), + cache: new InMemoryCache(), +}); + ReactDOM.render( - + + + , document.getElementById('root') -); +); \ No newline at end of file