@arc-publishing/sdk-identity
Version:
JS Identity SDK for working with Identity API
50 lines • 2.39 kB
JavaScript
import { __awaiter, __generator } from "tslib";
import JSONResponseHandler from '../serviceHelpers/JSONResponseHandler';
import { headers } from './constants';
import Identity from './identity';
import { getGoogleAuthInstance } from './initGoogleLogin';
import { isLegacyGoogleSetting } from './socialSignOnTypes';
export function isCheckSwgLoginResponse(object) {
return object.identityExists !== undefined;
}
export var checkSwgLogin = function (idToken) { return __awaiter(void 0, void 0, void 0, function () {
var googleIdToken;
var _a, _b, _c, _d, _e;
return __generator(this, function (_f) {
switch (_f.label) {
case 0:
googleIdToken = idToken;
if (!!googleIdToken) return [3, 2];
return [4, getGoogleAuthInstance()];
case 1:
_f.sent();
if (isLegacyGoogleSetting(Identity._google)) {
googleIdToken = (_e = (_d = (_c = (_b = (_a = Identity._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.apiOrigin, "/identity/public/v1/swg/checkloginexists"), {
method: 'POST',
headers: headers,
body: JSON.stringify({ token: googleIdToken })
})
.then(JSONResponseHandler)
.then(function (response) {
if (isCheckSwgLoginResponse(response)) {
return response;
}
else {
throw response;
}
})];
}
});
}); };
export default checkSwgLogin;
//# sourceMappingURL=checkSwgLogin.js.map