Skip to content

Instantly share code, notes, and snippets.

@JayKan
Forked from benawad/async.js
Created April 11, 2019 10:22
Show Gist options
  • Select an option

  • Save JayKan/85fec651dc350a200e3c586cae0e1c48 to your computer and use it in GitHub Desktop.

Select an option

Save JayKan/85fec651dc350a200e3c586cae0e1c48 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