Created
April 25, 2018 19:33
-
-
Save kensmash/af3765d2449039dfdc3f2f3e3640020a to your computer and use it in GitHub Desktop.
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
const setTokenAfterware = new ApolloLink((operation, forward) => { | |
const promises = forward(operation).map(async res => { | |
const context = operation.getContext(); | |
const { response: { headers } } = context; | |
const token = headers.get["x-token"]; | |
const refreshToken = headers.get["x-refresh-token"]; | |
if (token) { | |
await AsyncStorage.setItem("token", token); | |
} | |
if (refreshToken) { | |
await AsyncStorage.setItem("refreshToken", refreshToken); | |
} | |
return res; | |
}); | |
return Promise.all(promises); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment