Skip to content

Instantly share code, notes, and snippets.

@maticzav
Created December 30, 2017 13:55
Show Gist options
  • Save maticzav/b21d0817a18eb74962876b033ff24db0 to your computer and use it in GitHub Desktop.
Save maticzav/b21d0817a18eb74962876b033ff24db0 to your computer and use it in GitHub Desktop.
const authLink = new ApolloLink((operation, forward) => {
AsyncStorage.getItem('token').then(token => {
operation.setContext(({ headers = {} }) => ({
headers: {
...headers,
Authorization: token ? `Bearer ${token}` : null
}
}))
return forward(operation)
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment