@arc-publishing/sdk-identity
Version:
JS Identity SDK for working with Identity API
45 lines • 2.5 kB
JavaScript
import { __assign, __awaiter, __generator } from "tslib";
import { isAPIErrorResponse } from '../serviceHelpers/APIErrorResponse';
import JSONResponseHandler from '../serviceHelpers/JSONResponseHandler';
import Identity from './identity';
import { headers, logPrefix, PROFILE_STORAGE_KEY_EXPIRED_TIME } from './constants';
export default function unlinkSocialIdentity(grantType) {
var _a, _b, _c, _d;
return __awaiter(this, void 0, void 0, function () {
var isLoggedIn, userId;
return __generator(this, function (_e) {
switch (_e.label) {
case 0: return [4, Identity.isLoggedIn()];
case 1:
isLoggedIn = _e.sent();
if (!isLoggedIn) {
throw new Error("".concat(logPrefix, " Missing or invalid jwt"));
}
if (globalThis.google && grantType === 'google') {
userId = (_d = (_c = (_b = (_a = Identity === null || Identity === void 0 ? void 0 : Identity.userProfile) === null || _a === void 0 ? void 0 : _a.identities) === null || _b === void 0 ? void 0 : _b.find(function (i) { return i.type === 'Google'; })) === null || _c === void 0 ? void 0 : _c.userName) !== null && _d !== void 0 ? _d : '';
try {
globalThis.google.accounts.id.revoke(userId);
}
catch (e) {
throw new Error("[Arc Identity SDK]: Error revoking sign in with google user consent. ".concat(e));
}
}
return [2, fetch("".concat(Identity.apiOrigin, "/identity/public/v1/identity/").concat(grantType), {
method: 'DELETE',
headers: __assign({ Authorization: "Bearer ".concat(Identity.userIdentity.accessToken) }, headers)
})
.then(JSONResponseHandler)
.then(function (json) {
if (isAPIErrorResponse(json)) {
throw json;
}
else {
localStorage.removeItem(PROFILE_STORAGE_KEY_EXPIRED_TIME);
return json;
}
})];
}
});
});
}
//# sourceMappingURL=unlinkSocialIdentity.js.map