datocms-plugin-netlify-identity
Version:
A plugin that nicely displays Netlify identity user info instead of the raw ID
22 lines (16 loc) • 469 B
JavaScript
const fetch = require('node-fetch').default;
function fetchJson(url, token = null, customHeaders = {}) {
const headers = {};
if (customHeaders) {
Object.assign(headers, customHeaders);
}
if (token) {
Object.assign(headers, { authorization: `Bearer ${token}` });
}
return fetch(url, { headers })
.then(response => (
response.json()
.then(json => response.ok ? json : Promise.reject(json))
));
}
module.exports = fetchJson;