@arc-publishing/sdk-identity
Version:
JS Identity SDK for working with Identity API
127 lines • 5.78 kB
JavaScript
import { __awaiter, __generator } from "tslib";
import { socialLogin } from './socialSignOn';
import { isLegacyGoogleSetting } from './socialSignOnTypes';
import { getGoogleAuthInstance } from './initGoogleLogin';
import Identity from './identity';
export var deprecationMessage = 'Legacy Google Sign In will be deprecated on Dec 31, 2022. Use the new Arc Identity & Sign In With Google SDKs.';
export var googleSignOn = function (googleUser) { return __awaiter(void 0, void 0, void 0, function () {
var authInstance, googleUser_1, e, e_1;
var _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
console.error(deprecationMessage);
if (googleUser) {
return [2, signOnWithGoogleUser(googleUser)];
}
_b.label = 1;
case 1:
_b.trys.push([1, 7, , 8]);
if (!isLegacyGoogleSetting(Identity._google)) return [3, 5];
if (!!Identity._google.authInstance) return [3, 3];
return [4, getGoogleAuthInstance()];
case 2:
_b.sent();
_b.label = 3;
case 3:
authInstance = Identity._google.authInstance;
if (authInstance && authInstance.isSignedIn.get()) {
return [2, signOnWithGoogleUser(authInstance.currentUser.get())];
}
return [4, ((_a = Identity._google.authInstance) === null || _a === void 0 ? void 0 : _a.signIn({
prompt: 'select_account'
}))];
case 4:
googleUser_1 = _b.sent();
return [2, signOnWithGoogleUser(googleUser_1)];
case 5:
e = new Error('[Arc Identity SDK] - This method will only work with the legacy Google Sign In. Discontinue use of this method.');
console.error(e);
throw e;
case 6: return [3, 8];
case 7:
e_1 = _b.sent();
throw e_1;
case 8: return [2];
}
});
}); };
export var signOnSwgUser = function (_a) {
var idToken = _a.idToken, swgSubscriptionTokenResponse = _a.swgSubscriptionTokenResponse;
return __awaiter(void 0, void 0, void 0, function () {
var currentUser, idToken_1, e;
var _b, _c;
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
console.error(deprecationMessage);
if (!idToken) return [3, 1];
return [2, socialLogin('google', { credentials: idToken })];
case 1:
if (!swgSubscriptionTokenResponse) return [3, 2];
Identity.userIdentity = {
uuid: swgSubscriptionTokenResponse.profileId,
accessToken: swgSubscriptionTokenResponse.accessToken,
refreshToken: swgSubscriptionTokenResponse.refreshToken
};
return [2, Identity.heartbeat()];
case 2: return [4, getGoogleAuthInstance()];
case 3:
_d.sent();
if (isLegacyGoogleSetting(Identity._google)) {
if ((_b = Identity._google.authInstance) === null || _b === void 0 ? void 0 : _b.isSignedIn.get()) {
currentUser = (_c = Identity._google.authInstance) === null || _c === void 0 ? void 0 : _c.currentUser.get();
idToken_1 = currentUser.getAuthResponse().id_token;
return [2, socialLogin('google', { credentials: idToken_1 })];
}
else {
throw new Error('[Arc Identity SDK] - No google user logged in.');
}
}
else {
e = new Error('[Arc Identity SDK] - This method will only work with the legacy Google Sign In. Discontinue use of this method.');
console.error(e);
throw e;
}
_d.label = 4;
case 4: return [2];
}
});
});
};
var signOnWithGoogleUser = function (googleUser) {
console.error(deprecationMessage);
var googleIdToken = googleUser.getAuthResponse().id_token;
if (isLegacyGoogleSetting(Identity._google)) {
return socialLogin('google', {
credentials: googleIdToken
})
.then(function (userIdentity) {
if (isLegacyGoogleSetting(Identity._google)) {
if (Identity._google.onSuccess) {
Identity._google.onSuccess();
}
return userIdentity;
}
else {
throw new Error('[Arc Identity SDK] - This method will only work with the legacy Google Sign In. Discontinue use of this method.');
}
})
.catch(function (e) {
if (isLegacyGoogleSetting(Identity._google)) {
if (Identity._google.onFailure) {
Identity._google.onFailure();
}
throw e;
}
else {
throw new Error('[Arc Identity SDK] - This method will only work with the legacy Google Sign In. Discontinue use of this method.');
}
});
}
else {
throw new Error('[Arc Identity SDK] - This method will only work with the legacy Google Sign In. Discontinue use of this method.');
}
};
export default googleSignOn;
//# sourceMappingURL=googleSignOn.js.map