UPD: apollo wrapper wraps <App />
This commit is contained in:
parent
dfd1a2918f
commit
536783da6f
28
src/index.js
28
src/index.js
@ -4,9 +4,37 @@ import './index.css';
|
|||||||
import App from './App';
|
import App from './App';
|
||||||
import 'bootstrap/dist/css/bootstrap.min.css';
|
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(
|
ReactDOM.render(
|
||||||
<React.StrictMode>
|
<React.StrictMode>
|
||||||
|
<ApolloProvider client={client}>
|
||||||
<App />
|
<App />
|
||||||
|
</ApolloProvider>
|
||||||
</React.StrictMode>,
|
</React.StrictMode>,
|
||||||
document.getElementById('root')
|
document.getElementById('root')
|
||||||
);
|
);
|
Loading…
Reference in New Issue
Block a user