@arc-publishing/sdk-identity
Version:
JS Identity SDK for working with Identity API
48 lines • 2.75 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var APIErrorResponse_1 = require("../serviceHelpers/APIErrorResponse");
var JSONResponseHandler_1 = tslib_1.__importDefault(require("../serviceHelpers/JSONResponseHandler"));
var identity_1 = tslib_1.__importDefault(require("./identity"));
var constants_1 = require("./constants");
function unlinkSocialIdentity(grantType) {
var _a, _b, _c, _d;
return tslib_1.__awaiter(this, void 0, void 0, function () {
var isLoggedIn, userId;
return tslib_1.__generator(this, function (_e) {
switch (_e.label) {
case 0: return [4, identity_1.default.isLoggedIn()];
case 1:
isLoggedIn = _e.sent();
if (!isLoggedIn) {
throw new Error("".concat(constants_1.logPrefix, " Missing or invalid jwt"));
}
if (globalThis.google && grantType === 'google') {
userId = (_d = (_c = (_b = (_a = identity_1.default === null || identity_1.default === void 0 ? void 0 : identity_1.default.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_1.default.apiOrigin, "/identity/public/v1/identity/").concat(grantType), {
method: 'DELETE',
headers: tslib_1.__assign({ Authorization: "Bearer ".concat(identity_1.default.userIdentity.accessToken) }, constants_1.headers)
})
.then(JSONResponseHandler_1.default)
.then(function (json) {
if ((0, APIErrorResponse_1.isAPIErrorResponse)(json)) {
throw json;
}
else {
localStorage.removeItem(constants_1.PROFILE_STORAGE_KEY_EXPIRED_TIME);
return json;
}
})];
}
});
});
}
exports.default = unlinkSocialIdentity;
//# sourceMappingURL=unlinkSocialIdentity.js.map