Forge Paid App License validation

Hi,

I’m currently working on a Forge App and despite the fact I follow the documentation, licensing check do not seems to work in production. I did not managed to get a shared link to install it in a JIRA environment.

In my main function I call

 const isLicensed = useLicenseCheck();

then

return (
    <div className='app-container'>
      {isLicensed === false &&  <Text>App is not licensed</Text>}
      {isLicensed === true && ( 
      <div>...</div>
      </div>
)

useLicenseCheck is define as below

export default function useLicenseCheck(){
    const [licenseStatus, setLicenseStatus] = useState();

    useEffect(() => {
        invoke('getLicenseStatus').then( res => {
            setLicenseStatus(res)   
        }        
        )
    }, [])
    return licenseStatus
}

I registered my function in the resolver

resolver.define('getLicenseStatus', ( {context} ) => {
  return isLicenseActive(context)
})

Does this function has to be async ? It do not for ENV variable usage but does it in production ?

The isLicenseActive function is define like this

export const isLicenseActive =  (context) => {
    // Check for an environment variable that overrides the license state
    const override = process.env.LICENSE_OVERRIDE;
    if (typeof override !== 'undefined') {
        if (override.toLowerCase() === 'active') {
            return true;
        }
        if (override.toLowerCase() === 'inactive') {
            return false;
        }
    }
    /// option for UI Kit 2 front end
    return context && context.license && context.license.active;
}

It works fine in dev and staging but not in prod, it return {}, I would like to make sure it works before re-submitting the app. Any idea ? Should I create an async function for isLicenseActive ?

Regards

1 Like

Based on the useProductContext function signature in the docs, I’d say the return for isLicenseActive should be:

    /// option for UI Kit 2 front end
    return context && context.license && context.license.isActive;

It shouldn’t be necessary to make your invoked functions async. The invoke is async, but the resolvers themselves don’t have to be.

Yes thanks, I figured out that it was the issue. Example on the doc is not clear enough.

1 Like