Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add HTTP header to one request? #421

Open
michal-wierzba opened this issue May 31, 2023 · 1 comment
Open

How to add HTTP header to one request? #421

michal-wierzba opened this issue May 31, 2023 · 1 comment

Comments

@michal-wierzba
Copy link

How to add HTTP header to one request?

@Aryk
Copy link
Contributor

Aryk commented Jul 24, 2023

    // Authenticate the network into the current app, save the token for future API calls.
    setAuthorizationHeader(token: string) {
      const env = getEnv(self);

      if (token) {
        // https://github.com/mobxjs/mst-gql/issues/82#issuecomment-535046885
        env.gqlHttpClient.setHeaders({authorization: token});

        env.gqlWsClient.updateOptions({
          uri: constants.wsApiUrl + `?authorization=${token}`,
          // debugIncomingMessages: true,
        });

        // https://github.com/axios/axios#custom-instance-defaults
        env.uploadClient.defaults.headers.common['Authorization'] = token;
      } else {
        env.gqlHttpClient.setHeaders({});
        env.gqlWsClient.updateOptions({
          uri: constants.wsApiUrl,
          // debugIncomingMessages: true,
        });
        delete env.uploadClient.defaults.headers.common['Authorization']
      }
    },

Here is how I did it...does that help?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants