Skip to content

Instantly share code, notes, and snippets.

@lvidal1
Created July 18, 2017 20:19
Show Gist options
  • Save lvidal1/491f012f3411b15896d3a32fffeec40c to your computer and use it in GitHub Desktop.
Save lvidal1/491f012f3411b15896d3a32fffeec40c to your computer and use it in GitHub Desktop.
Apollo middleware with Authorization header
networkInterface.use([{
applyMiddleware(req, next) {
let authToken = localStorage.getItem("authToken");
if (authToken) {
req.options.headers = Object.assign({},req.options.headers, {
authorization: `Bearer ${authToken}`
});
}
next();
}
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment