From fdc7ae6a0a0cced82791bd03cf575f2fa68fca99 Mon Sep 17 00:00:00 2001 From: Wes Bos Date: Thu, 5 Apr 2018 14:00:50 -0400 Subject: clean up withData --- frontend/components/Signin.js | 3 ++- frontend/lib/withData.js | 34 +--------------------------------- 2 files changed, 3 insertions(+), 34 deletions(-) diff --git a/frontend/components/Signin.js b/frontend/components/Signin.js index e701e94..238e167 100644 --- a/frontend/components/Signin.js +++ b/frontend/components/Signin.js @@ -15,7 +15,8 @@ class Signin extends Component { e.preventDefault(); const res = await signin(); localStorage.setItem('token', res.data.signin.token); - client.query({ query: CURRENT_USER_QUERY, fetchPolicy: 'network-only' }); + // client.query({ query: CURRENT_USER_QUERY, fetchPolicy: 'network-only' }); + client.query({ query: CURRENT_USER_QUERY }); }; saveToState = e => { diff --git a/frontend/lib/withData.js b/frontend/lib/withData.js index ada9675..c823e62 100644 --- a/frontend/lib/withData.js +++ b/frontend/lib/withData.js @@ -5,10 +5,9 @@ import ApolloClient from 'apollo-boost'; const client = new ApolloClient({ uri: 'http://localhost:4444', - // cache: new InMemoryCache().restore(initialState || {}), ssrMode: !process.browser, // Disables forceFetch on the server (so queries are only run once) request: operation => { - console.log(operation); + // if we're in the client and the user has a token, send it along with the request if (typeof localStorage !== 'undefined' && localStorage.getItem('token')) { operation.setContext({ headers: { @@ -22,34 +21,3 @@ const client = new ApolloClient({ export { client }; export default withApollo({ client }); - -// OPTION 2 - -// import { withData } from 'next-apollo'; -// import { HttpLink } from 'apollo-link-http'; -// import { ApolloLink } from 'apollo-link'; - -// // can also be a function that accepts a `headers` object (SSR only) and returns a config -// const networkLink = new HttpLink({ -// uri: 'http://localhost:4444', // Server URL (must be absolute) -// opts: { -// credentials: 'same-origin', // Additional fetch() options like `credentials` or `headers` -// }, -// }); - -// const middlewareLink = new ApolloLink((operation, forward) => { -// if (typeof localStorage !== 'undefined' && localStorage.getItem('token')) { -// console.log('heyyy'); -// console.log(`Bearer ${localStorage.getItem('token')}`); -// operation.setContext({ -// headers: { -// authorization: `Bearer ${localStorage.getItem('token')}`, -// }, -// }); -// } -// return forward(operation); -// }); - -// const link = middlewareLink.concat(networkLink); - -// export default withData({ link }); -- cgit v1.3