Skip to content

Instantly share code, notes, and snippets.

@leighhalliday
Created March 10, 2019 12:34
Show Gist options
  • Save leighhalliday/f95afe7633531c131a51f325446f28f0 to your computer and use it in GitHub Desktop.
Save leighhalliday/f95afe7633531c131a51f325446f28f0 to your computer and use it in GitHub Desktop.
const authLink = setContext((_, oldContext) => {
  return produce(oldContext, draft => {
    if (!draft.headers) {
      draft.headers = {};
    }
    draft.headers["X-SOURCE"] = "browser";
    const token = cookie.get("token");
    if (token) {
      draft.headers["Authorization"] = `bearer ${token}`;
    }
  });
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment