question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Trying to use your example with apollo-boost while setting an authorization header, but contect ctx always seems to be undefined?

How do I require context while still using your HOC?

// apollo.js
import withApollo from 'next-with-apollo';
import ApolloClient from 'apollo-boost';
import getConfig from 'next/config';
import { getCookieJwt } from './auth';

const { publicRuntimeConfig } = getConfig();

export default withApollo(
  ({ ctx, headers }) => {
    return new ApolloClient({
      uri: `${publicRuntimeConfig.SERVER_URL}/api`,
      request: async operation => {
        const token = await getCookieJwt(ctx); //ctx is undefined
        operation.setContext({
          headers: {
            authorization: token ? `Bearer ${token}` : ''
          }
        });
      }
    });
  },
);

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:15 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
WickyNilliamscommented, Feb 7, 2019

Honestly, I feel like something more explicit would be better than inferring whether browser or not like this.

0reactions
ghostcommented, Jul 25, 2019

It has added the ctx - so yes looks like it addressed the problem. I do now have a new warning in the console below - though its unclear how this should be related to this fix, so ill continue to investigate. Posting here in case it makes sense to you (I don’t get this error using the next example implementation)

index.js:1 Warning: useLayoutEffect does nothing on the server, because its effect cannot be encoded into the server renderer’s output format.

Update: this seems reported elsewhere (#60 ) - will review that discussion.

Thankyou for addressing this so quickly all looks good.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: "ctx.cart is undefined" - Stack Overflow
Now issue here is that I'm not able to bind the data on cart.component.html side with 'cart', it generates this error- ERROR TypeError:...
Read more >
JSLink - javascript error: "ctx is undefined" - MSDN
The ctx object is a render context object that is created by the SPClientTemplates class defined in clienttemplates.js file. From what I've been ......
Read more >
Uncaught TypeError: this.ctx is undefined · Issue #2334 - GitHub
Describe the bug. Implement toast editor integration under the framework of wordpress's Block Editor, use the React Editor wrapper, ...
Read more >
Await undefined • REPL • Svelte
... noop, safe_not_equal, set_data, space, text } from "svelte/internal"; function create_catch_block(ctx) { let t_value = /*error*/ ctx[2] + ""; let t; ...
Read more >
Class ctx.page | SAP Help Portal
appli, {ctx.application}, parent application, undefined. comment, {string}, page comment, undefined. component, {Object}, optional technical component ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found