Scheduled trigger has no access to storage api

Hi,

I’m seeing inconsistent behavior when invoking the same function from within forge app and through the scheduled trigger, when it comes to retrieving from storage.

I.e.

Forge app - for instance when clicking a button in UI via onClick={await fetchTips()}:

export async function fetchTips() {
  var value = await storage.get('field123')
  console.log(value) // shows "XXXXXX" in log
}

Scheduled trigger for fetchTips:

// shows "undefined" in log

What I see here is that somehow Forge app and scheduled trigger do not have the same level of access to storage. I used this functionality a lot in the past and it worked fine, now I wonder if there were any changes recently? Any ideas why the scheduled trigger can’t retrieve the same storage entry that the app can?

Thanks

Hi @IgorAndriushchenkp,

From your description it sounds like it’s an unexpected behaviour.
There shouldn’t have been any changes recently that should cause this behaviour.

Could you provide some more details about what your scheduled trigger look like?

Hi @DganitZuriel, I am new to Forge / the community, so I can’t speak to how this worked historically but I see the same behaviour. I have a really simple manifest with a webtrigger and scheduledTrigger that call the same function.

The function looks like this:

export async function run(event, context) {
    const triggerType = 'cron';
    if (event.body) {
        triggerType = 'hook'
    }

    console.log(`Event triggered via ${triggerType}`)
    console.log("Fetching setting:")

    const setting = await storage.getSecret('setting');
    console.log(setting)

    return {
        statusCode: 200,
        statusText: 'Sync Triggered'
    }
}

With the tunnel open I can trigger via webhook and see the setting printed to the console, when it’s triggered via the cron I see:

ERROR   00:16:35.654  2fa9cab5fb7c64a0  Authentication error
Error: Authentication error
    at Function.forStatus (webpack://cmdb-plugin-jamf/node_modules/@forge/storage/out/errors.js:30)
    at getResponseBody (webpack://cmdb-plugin-jamf/node_modules/@forge/storage/out/global-storage.js:14)
    at GlobalStorage.query (webpack://cmdb-plugin-jamf/node_modules/@forge/storage/out/global-storage.js:89)
    at async GlobalStorage.getInternal (webpack://cmdb-plugin-jamf/node_modules/@forge/storage/out/global-storage.js:75)
    at async Sync (webpack://cmdb-plugin-jamf/src/sync.jsx:27)
    at async run (webpack://cmdb-plugin-jamf/src/trigger.jsx:15)

I can work around this by calling the webTrigger from the scheduledTrigger with fetch but that smells a little bit.