Skip to content

Instantly share code, notes, and snippets.

@skiph

skiph/Approov.js

Last active May 2, 2018
Embed
What would you like to do?
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