@arc-publishing/sdk-identity
Version:
JS Identity SDK for working with Identity API
42 lines • 2.02 kB
JavaScript
import { __assign, __awaiter, __generator } from "tslib";
import Identity from './identity';
import { isUserIdentity } from './userIdentity';
import { headers as defaultHeaders, PROFILE_STORAGE_KEY_EXPIRED_TIME } from './constants';
import JSONResponseHandler from '../serviceHelpers/JSONResponseHandler';
export function socialLogin(type, identity) {
return __awaiter(this, void 0, void 0, function () {
var headers;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
headers = __assign({}, defaultHeaders);
if (!(Identity.userIdentity &&
Identity.userIdentity.accessToken &&
Identity.userIdentity.refreshToken)) return [3, 2];
return [4, Identity.heartbeat()];
case 1:
_a.sent();
headers['Authorization'] = "Bearer ".concat(Identity.userIdentity.accessToken);
_a.label = 2;
case 2: return [2, fetch("".concat(Identity.apiOrigin, "/identity/public/v1/auth/login"), {
method: 'POST',
headers: headers,
body: JSON.stringify(__assign(__assign({}, identity), { userName: '', grantType: type }))
})
.then(JSONResponseHandler)
.then(function (json) {
if (isUserIdentity(json)) {
localStorage.removeItem(PROFILE_STORAGE_KEY_EXPIRED_TIME);
Identity.userIdentity = json;
window.postMessage({ type: 'ARC_LOGIN_SUCCESS', grantType: type }, '*');
return json;
}
else {
throw json;
}
})];
}
});
});
}
//# sourceMappingURL=socialSignOn.js.map