UNPKG

@arc-publishing/sdk-identity

Version:
39 lines 1.76 kB
import { __assign, __awaiter, __generator } from "tslib"; import JSONResponseHandler from '../serviceHelpers/JSONResponseHandler'; import { isUserProfile } from './userProfile'; import Identity from './identity'; import { headers, logPrefix } from './constants'; export default function updateUserProfile(profile) { return __awaiter(this, void 0, void 0, function () { var isLoggedIn; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4, Identity.isLoggedIn()]; case 1: isLoggedIn = _a.sent(); if (!isLoggedIn) { throw new Error("".concat(logPrefix, " Missing or invalid jwt")); } if (isUserProfile(profile)) { delete profile.uuid; } return [2, fetch("".concat(Identity.apiOrigin, "/identity/public/v1/profile"), { method: 'PATCH', headers: __assign({ Authorization: "Bearer ".concat(Identity.userIdentity.accessToken) }, headers), body: JSON.stringify(profile) }) .then(JSONResponseHandler) .then(function (json) { if (isUserProfile(json)) { Identity.userProfile = json; return Identity.userProfile; } else { throw json; } })]; } }); }); } //# sourceMappingURL=updateUserProfile.js.map