Last active
May 2, 2018 19:52
-
-
Save skiph/01600acc918c58152e1772cba68b90ac to your computer and use it in GitHub Desktop.
RNDemo - Approov module wrapper
This file contains 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
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