@arc-publishing/sdk-identity
Version:
JS Identity SDK for working with Identity API
40 lines • 1.81 kB
JavaScript
import { __assign, __awaiter, __generator } from "tslib";
import { headers, logPrefix } from './constants';
import Identity from './identity';
import JSONResponseHandler from '../serviceHelpers/JSONResponseHandler';
import { isAPIErrorResponse } from '../serviceHelpers/APIErrorResponse';
export function getUserSettings() {
return __awaiter(this, void 0, void 0, function () {
var isLoggedIn;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!!Identity.userSettings) return [3, 2];
return [4, Identity.isLoggedIn()];
case 1:
isLoggedIn = _a.sent();
if (!isLoggedIn) {
throw new Error("".concat(logPrefix, " Missing or invalid jwt"));
}
return [2, fetch("".concat(Identity.apiOrigin, "/identity/public/v1/user/settings"), {
method: 'GET',
cache: 'no-cache',
headers: __assign({ Authorization: "Bearer ".concat(Identity.userIdentity.accessToken) }, headers)
})
.then(JSONResponseHandler)
.then(function (json) {
if (isAPIErrorResponse(json)) {
throw json;
}
else {
Identity.userSettings = json;
return json;
}
})];
case 2: return [2, Identity.userSettings];
}
});
});
}
export default getUserSettings;
//# sourceMappingURL=getUserSettings.js.map