@arc-publishing/sdk-identity
Version:
JS Identity SDK for working with Identity API
55 lines • 2.79 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.checkSwgLogin = exports.isCheckSwgLoginResponse = void 0;
var tslib_1 = require("tslib");
var JSONResponseHandler_1 = tslib_1.__importDefault(require("../serviceHelpers/JSONResponseHandler"));
var constants_1 = require("./constants");
var identity_1 = tslib_1.__importDefault(require("./identity"));
var initGoogleLogin_1 = require("./initGoogleLogin");
var socialSignOnTypes_1 = require("./socialSignOnTypes");
function isCheckSwgLoginResponse(object) {
return object.identityExists !== undefined;
}
exports.isCheckSwgLoginResponse = isCheckSwgLoginResponse;
var checkSwgLogin = function (idToken) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
var googleIdToken;
var _a, _b, _c, _d, _e;
return tslib_1.__generator(this, function (_f) {
switch (_f.label) {
case 0:
googleIdToken = idToken;
if (!!googleIdToken) return [3, 2];
return [4, (0, initGoogleLogin_1.getGoogleAuthInstance)()];
case 1:
_f.sent();
if ((0, socialSignOnTypes_1.isLegacyGoogleSetting)(identity_1.default._google)) {
googleIdToken = (_e = (_d = (_c = (_b = (_a = identity_1.default._google) === null || _a === void 0 ? void 0 : _a.authInstance) === null || _b === void 0 ? void 0 : _b.currentUser) === null || _c === void 0 ? void 0 : _c.get()) === null || _d === void 0 ? void 0 : _d.getAuthResponse()) === null || _e === void 0 ? void 0 : _e.id_token;
}
else {
}
_f.label = 2;
case 2:
if (!googleIdToken) {
console.error('No Google ID token found. Either the user is not logged in with Google, or the Google Auth2 SDK is incorrectly loaded.');
return [2, { identityExists: false }];
}
return [2, fetch("".concat(identity_1.default.apiOrigin, "/identity/public/v1/swg/checkloginexists"), {
method: 'POST',
headers: constants_1.headers,
body: JSON.stringify({ token: googleIdToken })
})
.then(JSONResponseHandler_1.default)
.then(function (response) {
if (isCheckSwgLoginResponse(response)) {
return response;
}
else {
throw response;
}
})];
}
});
}); };
exports.checkSwgLogin = checkSwgLogin;
exports.default = exports.checkSwgLogin;
//# sourceMappingURL=checkSwgLogin.js.map