Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions src/services/entitlements.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,24 @@ define(function (require, exports, module) {
});
}

let effectiveEntitlements = null;
async function _getEffectiveEntitlements() {
if(effectiveEntitlements){
return effectiveEntitlements;
}
const entitlements = await LoginService.getEffectiveEntitlements();
effectiveEntitlements = entitlements;
return entitlements;
}

/**
* Get the plan details from entitlements with fallback to free plan defaults. If the user is
* in pro trial(isInProTrial API), then paidSubscriber will always be true as we need to treat user as paid.
* you should use isInProTrial API to check if user is in pro trial if some trial-related logic needs to be done.
* @returns {Promise<Object>} Plan details object
*/
async function getPlanDetails() {
const entitlements = await LoginService.getEffectiveEntitlements();
const entitlements = await _getEffectiveEntitlements();

if (entitlements && entitlements.plan) {
return entitlements.plan;
Expand All @@ -97,7 +107,7 @@ define(function (require, exports, module) {
* @returns {Promise<boolean>} True if user is in pro trial, false otherwise
*/
async function isInProTrial() {
const entitlements = await LoginService.getEffectiveEntitlements();
const entitlements = await _getEffectiveEntitlements();
return !!(entitlements && entitlements.isInProTrial);
}

Expand All @@ -106,13 +116,13 @@ define(function (require, exports, module) {
* @returns {Promise<number>} Number of remaining trial days
*/
async function getTrialRemainingDays() {
const entitlements = await LoginService.getEffectiveEntitlements();
const entitlements = await _getEffectiveEntitlements();
return entitlements && entitlements.trialDaysRemaining ? entitlements.trialDaysRemaining : 0;
}

/**
* Get current raw entitlements. Should not be used directly, use individual feature entitlement instead
* like getLiveEditEntitlement.
* like getLiveEditEntitlement. Raw entitlements are server set and will not contain trial info.
* @returns {Promise<Object|null>} Raw entitlements object or null
*/
async function getRawEntitlements() {
Expand Down Expand Up @@ -142,7 +152,7 @@ define(function (require, exports, module) {
* }
*/
async function getLiveEditEntitlement() {
const entitlements = await LoginService.getEffectiveEntitlements();
const entitlements = await _getEffectiveEntitlements();

if (entitlements && entitlements.entitlements && entitlements.entitlements.liveEdit) {
return entitlements.entitlements.liveEdit;
Expand All @@ -168,6 +178,7 @@ define(function (require, exports, module) {
LoginService = KernalModeTrust.loginService;
// Set up event forwarding from LoginService
LoginService.on(LoginService.EVENT_ENTITLEMENTS_CHANGED, function() {
effectiveEntitlements = null;
Entitlements.trigger(EVENT_ENTITLEMENTS_CHANGED);
});
}
Expand Down
13 changes: 8 additions & 5 deletions src/services/login-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,10 @@ define(function (require, exports, module) {


/**
* Get entitlements from API or cache
* Returns null if user is not logged in
* Get entitlements from API or disc cache.
* @param {string} forceRefresh If provided will always fetch from server and bypass cache. Use rarely like
* when a user logs in/out/some other user activity/ account-related events.
* Returns null if the user is not logged in
*/
async function getEntitlements(forceRefresh = false) {
// Return null if not logged in
Expand Down Expand Up @@ -250,7 +252,8 @@ define(function (require, exports, module) {
try {
const accountBaseURL = LoginService.getAccountBaseURL();
const language = brackets.getLocale();
let url = `${accountBaseURL}/getAppEntitlements?lang=${language}`;
const currentVersion = window.AppConfig.apiVersion || "1.0.0";
let url = `${accountBaseURL}/getAppEntitlements?lang=${language}&version=${currentVersion}`;
let fetchOptions = {
method: 'GET',
headers: {
Expand Down Expand Up @@ -413,8 +416,8 @@ define(function (require, exports, module) {
}

/**
* Get effective entitlements for determining feature availability throughout the app.
* This is the primary API that should be used across Phoenix to check entitlements and enable/disable features.
* Get effective entitlements for determining feature availability.
* This is for internal use only. All consumers in phoenix code should use `KernalModeTrust.Entitlements` APIs.
*
* @returns {Promise<Object|null>} Entitlements object or null if not logged in and no trial active
*
Expand Down
11 changes: 8 additions & 3 deletions src/services/readme-login-browser-no_dist.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,22 @@ For testing with a local account server instance:
- Start your local account development stack on `localhost:5000`
- Ensure all login endpoints are properly configured

3. **Login and Copy Session:**
Now just visit login server at `http://localhost:5000` and login. It should work with phoenix code dev server
at https://localhost:8000/src when you run phoenix code dev server via `npm run serve`. This works without any
manual cookie copy needed as the dev server sets cookies localhost wide. But if that didnt work, please see
manual cookie copy instructions below.

1. **Login and Copy Session:**
- Navigate to `http://localhost:5000` in browser
- Login with test credentials
- Copy `session` cookie value from DevTools

4. **Set Cookie in Phoenix App:**
2. **Set Cookie in Phoenix App:**
- Navigate to `http://localhost:8000/src/`
- Open Chrome DevTools → Application → Cookies
- Create `session` cookie with copied value (same process as above)

5. **Verify Local Integration:**
3. **Verify Local Integration:**
- API calls from localhost:8000 now route through serve-proxy.js to localhost:5000
- Authentication should work with local account server

Expand Down
Loading