Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { InMemoryCache } from 'apollo-cache-inmemory';
import Cookies from 'js-cookie';
import fragmentMatcher from 'tools/fragmentMatcher';
import { TOKEN_KEY } from 'utils/constants';
import apolloClient from 'apollo/client';
const headers = {};
const authToken = Cookies.get(TOKEN_KEY);
if (authToken) {
headers.Authorization = `Bearer ${authToken}`;
}
export default apolloClient('/graphql', headers, {
cache: new InMemoryCache({ fragmentMatcher }).restore(window.__APOLLO_STATE__),
});
export default (req, res, next) => {
const port = parseInt(KYT.SERVER_PORT, 10);
const uri = `http://localhost:${port}/graphql`;
const headers = {};
if (req.cookies.draftAuthToken) {
headers.Authorization = `Bearer ${req.cookies.draftAuthToken}`;
}
res.locals.client = apolloClient(uri, headers, { ssrMode: true });
next();
};