summaryrefslogtreecommitdiffstats
path: root/frontend/lib
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/lib')
-rw-r--r--frontend/lib/withData.js34
1 files changed, 34 insertions, 0 deletions
diff --git a/frontend/lib/withData.js b/frontend/lib/withData.js
index 697cf79..5a32fe3 100644
--- a/frontend/lib/withData.js
+++ b/frontend/lib/withData.js
@@ -9,7 +9,10 @@ export default withApollo({
// cache: new InMemoryCache().restore(initialState || {}),
// ssrMode: !process.browser, // Disables forceFetch on the server (so queries are only run once)
request: operation => {
+ console.log('hey');
if (typeof localStorage !== 'undefined' && localStorage.getItem('token')) {
+ console.log('heyyy');
+ console.log(`Bearer ${localStorage.getItem('token')}`);
operation.setContext({
headers: {
authorization: `Bearer ${localStorage.getItem('token')}`,
@@ -19,3 +22,34 @@ export default withApollo({
},
}),
});
+
+// 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 });