Skip to content

Instantly share code, notes, and snippets.

@skiph
Last active May 2, 2018 19:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skiph/01600acc918c58152e1772cba68b90ac to your computer and use it in GitHub Desktop.
Save skiph/01600acc918c58152e1772cba68b90ac to your computer and use it in GitHub Desktop.
RNDemo - Approov module wrapper
import {NativeModules} from 'react-native';
const fetchWithToken = (input, options) => {
return NativeModules.Approov.fetchApproovToken(input)
.then(token => {
let optionsA = (options? {...options, headers:{ ...options.headers}}:{headers: {}});
optionsA.headers['Approov-Token'] = token;
return fetch(input, optionsA)
.then((response) => {
if (response.ok) {
return response;
}
else {
throw new Error('HTTP response status is ' + response.status);
}
})
.catch((error) => {
throw error;
})
})
.catch((error) => {
throw error;
})
};
const Approov = Object.assign({ fetch: fetchWithToken }, NativeModules.Approov);
export default Approov;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment