UNPKG

@arc-publishing/sdk-identity

Version:
46 lines 2.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.socialLogin = void 0; var tslib_1 = require("tslib"); var identity_1 = tslib_1.__importDefault(require("./identity")); var userIdentity_1 = require("./userIdentity"); var constants_1 = require("./constants"); var JSONResponseHandler_1 = tslib_1.__importDefault(require("../serviceHelpers/JSONResponseHandler")); function socialLogin(type, identity) { return tslib_1.__awaiter(this, void 0, void 0, function () { var headers; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: headers = tslib_1.__assign({}, constants_1.headers); if (!(identity_1.default.userIdentity && identity_1.default.userIdentity.accessToken && identity_1.default.userIdentity.refreshToken)) return [3, 2]; return [4, identity_1.default.heartbeat()]; case 1: _a.sent(); headers['Authorization'] = "Bearer ".concat(identity_1.default.userIdentity.accessToken); _a.label = 2; case 2: return [2, fetch("".concat(identity_1.default.apiOrigin, "/identity/public/v1/auth/login"), { method: 'POST', headers: headers, body: JSON.stringify(tslib_1.__assign(tslib_1.__assign({}, identity), { userName: '', grantType: type })) }) .then(JSONResponseHandler_1.default) .then(function (json) { if ((0, userIdentity_1.isUserIdentity)(json)) { localStorage.removeItem(constants_1.PROFILE_STORAGE_KEY_EXPIRED_TIME); identity_1.default.userIdentity = json; window.postMessage({ type: 'ARC_LOGIN_SUCCESS', grantType: type }, '*'); return json; } else { throw json; } })]; } }); }); } exports.socialLogin = socialLogin; //# sourceMappingURL=socialSignOn.js.map