UPD: apollo wrapper wraps <App />
This commit is contained in:
parent
dfd1a2918f
commit
536783da6f
32
src/index.js
32
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(
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
<ApolloProvider client={client}>
|
||||
<App />
|
||||
</ApolloProvider>
|
||||
</React.StrictMode>,
|
||||
document.getElementById('root')
|
||||
);
|
||||
);
|
Loading…
Reference in New Issue
Block a user