Skip to content

Instantly share code, notes, and snippets.

@benawad
Forked from kensmash/Apollo Afterware Async attempt
Last active July 8, 2020 18:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save benawad/9444bd217f2a98336bc347d42c87c1b1 to your computer and use it in GitHub Desktop.
Save benawad/9444bd217f2a98336bc347d42c87c1b1 to your computer and use it in GitHub Desktop.
const setTokenAfterware = new ApolloLink(async (operation, forward) => {
return 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;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment