Test licensing: env variable LICENSE_OVERRIDE = active still returns license.isActive == false

Hi there,

I just wanted to doublecheck.

I followed the docs: https://developer.atlassian.com/platform/marketplace/listing-forge-apps/#testing-your-app-with-different-license-states

Environment Variable is set to LICENSE_OVERRIDE = active.

Now I expected that this turns license.isActive == true, but instead I am still seing license.isActive == false.

In the web I found someone who in his code is checking directly for the environment variable LICENSE_OVERRIDE before license.isActive == false for testing. That is the blog entry: Developing a Jira App: Three Tips for Atlassian Forge App Development — Moser Consulting

However, that seemed a bit cumbersome since I would prefer to directly manipulate license.isActive.

The way I am currently checking:

  if(context.license && !context.license.isActive){
    throw new Error("License is not active");
  }
1 Like

How did you manage to get access to the license object at all?
I also followed the instructions on the page you mentioned and did a

forge install --environment development --license inactive --upgrade
forge deploy --environment development

In the context of our Forge backend, there is no license object. The next best thing is

"accountType": "licensed"

However, this value is always “licensed”, no matter what I put in LICENSE_OVERRIDE or the license parameter in “forge install”.

1 Like

One thing I found in the documentation on https://developer.atlassian.com/platform/forge/cli-reference/variables-set/

After setting or updating an environment variable with forge variables set, you must run forge deploy for the changes to take effect in your deployed app. Environment variable updates are not applied until the next deployment. Redeploying your app will ensure your app uses the latest values in its runtime environment.

Maybe that solves your issue.

Hi Stefan, thanks for you reply!

One thing is setting the environment variables as you sent it, which works fine for me. However, the LICENSE_OVERRIDE = active does not have any effect for me although I redeployed.

Accessing the object works as written in the docs:

   import Resolver from "@forge/resolver";
   const resolver = new Resolver;

   resolver.define("checkLicense", ({ context }) => {
      return context.license && context.license.isActive;
   }

To conclude, it seems that this is the way to go:

Although I could be naming my env variable then as I wish since the LICENSE_OVERRIDE Variable does not have any effect in the atlassian contect.

Thanks for the information! I was wondering what I am doing wrong, because setting LICENSE_OVERRIDE has no effect for me as well. It’s good to know that I’m not the only one for whom it’s not working.

Many thanks for the idea to check the environment variable directly! I’ve added an environment check just to be sure that this part never gets executed in production:

resolver.define('checkLicense', ({ context }) => {
  const override = process.env.LICENSE_OVERRIDE;
  if (context.environmentType !== 'PRODUCTION' && typeof override !== 'undefined') {
    const overrideStr = override.toLowerCase();
    if (overrideStr === 'active') {
      return true;
    }
    return false;
  }
  
  return context.license && context.license.isActive;
});

I’m calling it like this from the frontend:

    const hasValidLicense = async () => {
        if (isLicensed.current === null) {
            isLicensed.current = await invoke('checkLicense');
        }
        return isLicensed.current;
    }

The context object in the backend is injected by Forge, and there’s no license information whatsoever.

Since you said there is not license information:

As you already wrote, I did this step first as well:

forge install --environment development --license inactive --upgrade
forge deploy --environment development

Then for my Backend I initialise context like that:

const App = () => {
    const context = useProductContext();

then I check it and isActive returns false:

// Check license first
if (context && context.license && !context.license.isActive) {
    setErrorMessage('License is not active. Please activate your license to use this feature.');
    return;
}

Thank you very much for pointing out that the context needs to be initialized! That’s the step I was missing. I’ll put that in right away and see what changes.

No luck there, the license in the productContext is null as well:

    "accountId": "123",
    "license": null,
    "timezone": "Europe/Berlin",

I guess that’s because useProductContext is a hook for UI Kit, whereas we are using a Custom UI interface. So I’ll stick to the implementation in the Forge backend and hope that the license object is correctly populated there. I hate not being able to test this properly.