couchdb-get-authorised-user-node
Version:
couchdb getAuthorisedUser for node
30 lines (25 loc) • 666 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
// ask the couchdb's _session API to authorise a user
exports.default = function getAuthorisedUser(endpoint, Authorization) {
return Promise.resolve().then(function () {
return fetch(endpoint, {
headers: {
Authorization,
'Content-Type': 'application/json'
}
});
}).then(function (_resp) {
const res = _resp;
return res.json();
}).then(function (_resp) {
const data = _resp;
if (data.ok) {
return data;
} else {
throw Error(`can't authenticate against couchdb's _session API: ${ data.error }`);
}
});
};