Skip to content

Instantly share code, notes, and snippets.

@tudorilisoi
Last active December 13, 2018 18:30
Show Gist options
  • Save tudorilisoi/9533c3a56cedcaf2e6a76512eaf443bd to your computer and use it in GitHub Desktop.
Save tudorilisoi/9533c3a56cedcaf2e6a76512eaf443bd to your computer and use it in GitHub Desktop.
function fetchProtectedData(url, opts = {}) {
let headers = {
'Content-Type': 'application/json',
}
if (JWT_TOKEN) {
headers = {
...headers,
'Authorization': `Bearer ${JWT_TOKEN}`,
}
}
let finalOpts = {
...opts,
headers
}
return $.ajax(url, finalOpts)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment