Created
July 18, 2017 20:19
-
-
Save lvidal1/491f012f3411b15896d3a32fffeec40c to your computer and use it in GitHub Desktop.
Apollo middleware with Authorization header
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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