Skip to content

Commit b1bed56

Browse files
committed
chore: add Entitlements.loginToAccount convenience api
1 parent e5e8564 commit b1bed56

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

src/services/entitlements.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,23 @@ define(function (require, exports, module) {
5353
return LoginService.isLoggedIn();
5454
}
5555

56+
/**
57+
* Attempts to sign in to the user's account if the user is not already logged in.
58+
* You should listen to `EVENT_ENTITLEMENTS_CHANGED` to know when the login status changes. This function
59+
* returns immediately and does not wait for the login process to complete.
60+
*
61+
* @return {void} Does not return a value.
62+
*/
63+
function loginToAccount() {
64+
if(isLoggedIn()){
65+
return;
66+
}
67+
KernalModeTrust.loginService.signInToAccount()
68+
.catch(function(err){
69+
console.error("Error signing in to account", err);
70+
});
71+
}
72+
5673
/**
5774
* Get the plan details from entitlements with fallback to free plan defaults. If the user is
5875
* in pro trial(isInProTrial API), then paidSubscriber will always be true as we need to treat user as paid.
@@ -164,7 +181,8 @@ define(function (require, exports, module) {
164181
isInProTrial,
165182
getTrialRemainingDays,
166183
getRawEntitlements,
167-
getLiveEditEntitlement
184+
getLiveEditEntitlement,
185+
loginToAccount
168186
};
169187
}
170188

@@ -173,6 +191,7 @@ define(function (require, exports, module) {
173191

174192
// Add functions to secure exports
175193
Entitlements.isLoggedIn = isLoggedIn;
194+
Entitlements.loginToAccount = loginToAccount;
176195
Entitlements.getPlanDetails = getPlanDetails;
177196
Entitlements.isInProTrial = isInProTrial;
178197
Entitlements.getTrialRemainingDays = getTrialRemainingDays;

src/services/login-browser.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,9 @@ define(function (require, exports, module) {
417417
if (!Phoenix.isNativeApp) {
418418
// kernal exports
419419
// Add to existing KernalModeTrust.loginService from login-service.js
420+
// isLoggedIn API shouldn't be used outside loginService, please use Entitlements.isLoggedIn API.
420421
LoginService.isLoggedIn = isLoggedIn;
422+
// signInToAccount API shouldn't be used outside loginService, please use Entitlements.loginToAccount API.
421423
LoginService.signInToAccount = signInToBrowser;
422424
LoginService.signOutAccount = signOutBrowser;
423425
LoginService.getProfile = getProfile;

src/services/login-desktop.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,9 @@ define(function (require, exports, module) {
413413
// Only set exports for native apps to avoid conflict with browser login
414414
if (Phoenix.isNativeApp) {
415415
// kernal exports - add to existing KernalModeTrust.loginService from login-service.js
416+
// isLoggedIn API shouldn't be used outside loginService, please use Entitlements.isLoggedIn API.
416417
LoginService.isLoggedIn = isLoggedIn;
418+
// signInToAccount API shouldn't be used outside loginService, please use Entitlements.loginToAccount API.
417419
LoginService.signInToAccount = signInToAccount;
418420
LoginService.signOutAccount = signOutAccount;
419421
LoginService.getProfile = getProfile;

0 commit comments

Comments
 (0)