Progress with authentication tolen
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import './styles/index.css';
|
||||
import { AUTH_TOKEN } from './constants';
|
||||
import App from './components/App';
|
||||
import { BrowserRouter } from 'react-router-dom';
|
||||
import { setContext } from '@apollo/client/link/context';
|
||||
// import * as serviceWorker from './serviceWorker';
|
||||
|
||||
import {
|
||||
@@ -16,8 +18,19 @@ const httpLink = createHttpLink({
|
||||
uri: 'http://localhost:4000/graphql'
|
||||
});
|
||||
|
||||
const authLink = setContext((_, { headers }) => {
|
||||
const token = localStorage.getItem(AUTH_TOKEN);
|
||||
return {
|
||||
headers: {
|
||||
...headers,
|
||||
authorization: token ? `Bearer ${token}` : ''
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
const client = new ApolloClient({
|
||||
link: httpLink,
|
||||
link: authLink.concat(httpLink),
|
||||
// link: httpLink,
|
||||
cache: new InMemoryCache()
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user