-
-
Save ifiokjr/26fc8b34be94a02413aa5c2c421cd7d5 to your computer and use it in GitHub Desktop.
An Apollo Link for setting an auth token 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
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