Created
November 11, 2017 08:48
-
-
Save jaydenseric/885c781f18f54992cbbf34873c7081e5 to your computer and use it in GitHub Desktop.
An Apollo Link for setting an auth token header.
This file contains 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
import { ApolloLink } from 'apollo-link' | |
const createTokenLink = ({ getToken }) => | |
new ApolloLink((operation, forward) => { | |
const token = getToken() | |
if (token) | |
operation.setContext({ | |
headers: { | |
authorization: `Bearer ${token}` | |
} | |
}) | |
return forward(operation) | |
}) | |
export default createTokenLink |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment