mirror of
https://github.com/hazemKrimi/crimson-quirks-ui.git
synced 2026-05-02 02:30:29 +00:00
Update apollo config
This commit is contained in:
+22
-4
@@ -1,6 +1,12 @@
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import { ApolloClient, InMemoryCache, ApolloProvider } from '@apollo/client';
|
||||
import {
|
||||
ApolloClient,
|
||||
InMemoryCache,
|
||||
createHttpLink,
|
||||
ApolloProvider,
|
||||
} from '@apollo/client';
|
||||
import { setContext } from '@apollo/client/link/context';
|
||||
import { ThemeProvider } from 'styled-components';
|
||||
import { BrowserRouter } from 'react-router-dom';
|
||||
import { theme } from './themes';
|
||||
@@ -8,12 +14,24 @@ import App from './App';
|
||||
import GlobalStyles from './GlobalStyles';
|
||||
import reportWebVitals from './reportWebVitals';
|
||||
|
||||
const client = new ApolloClient({
|
||||
const httpLink = createHttpLink({
|
||||
uri: process.env.REACT_APP_GRAPHQL_API,
|
||||
cache: new InMemoryCache(),
|
||||
});
|
||||
|
||||
const authLink = setContext((_, { headers }) => {
|
||||
const token = localStorage.getItem('token');
|
||||
|
||||
return {
|
||||
headers: {
|
||||
authorization: localStorage.getItem('token')!,
|
||||
...headers,
|
||||
authorization: token || '',
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
const client = new ApolloClient({
|
||||
link: authLink.concat(httpLink),
|
||||
cache: new InMemoryCache(),
|
||||
});
|
||||
|
||||
ReactDOM.render(
|
||||
|
||||
Reference in New Issue
Block a user