#Unable to authentify, whether it's with configure() or env variables

1 messages · Page 1 of 1 (latest)

strange escarp
#

I'm implementing trigger v3 on my nuxt 3 app deployed on cloudflare pages.

CF pages environment variables aren't provided through process.env, so I need to perform manual setup from what I understood

But my issue is that calling configure() does nothing. It works perfectly fine locally, in dev mode, but when I deploy in cloudflare & run the following code :

configure({
      accessToken: useRuntimeConfig().trigger.accessToken,
    })

    await tasks.batchTrigger<typeof assessmentResultTask>(
      'assessment-result',
      fullAssessments.map(a => ({ payload: { assessmentId: a.id } })),
    )

I get the following error :

You need to set the TRIGGER_SECRET_KEY environment variable. See https://trigger.dev/docs/management/overview#authentication

(I previously ran the configure() in a middleware before the actual endpoint handler calling batchTrigger runs, but since it wasn't working I moved it right above the batchTrigger call, but I still can't get it to work

I have the latest vers. installed of the package : "@trigger.dev/sdk": "3.3.7"

I even tried to set the access token in the env context, still getting the same error :

  process.env.TRIGGER_ACCESS_TOKEN = useRuntimeConfig().trigger.accessToken
    process.env.TRIGGER_SECRET_KEY = useRuntimeConfig().trigger.accessToken
inner sonnet
#

It looks like you’re using the same value for the acccess token and secret key. You should configure with the secret key which you can find in the API keys page in the dashboard

strange escarp
#

@inner sonnet Hi, thanks fcor the answer. Sorry I shouldn't have show this it's misleading. I basically tried to set both because it wasn't working with either access token or secret key

I'm already using the correct values, the issue here being that configure() is not working

inner sonnet
#

it’s secretKey in the configure call too:

configure({
// this is the default and if the TRIGGER_SECRET_KEY environment variable is set, can omit calling configure
secretKey: process.env["TRIGGER_SECRET_KEY"],
});

#

Obv ignore process.env

#

I’m on my phone but this does work with CF if you set it

strange escarp
#

secretKey is flagged as deprecated
@deprecated — Use accessToken instead.
But I also tried this, same issue

#

I'll hook up a minimal reproduction

strange escarp
#

@inner sonnet I've set a minimal reproduction of the issue :
https://github.com/ChronicStone/nuxt-cloudflare-trigger.dev-repro

Fresh nuxt 3 app deployed in cloudflare-pages
Dead simple example task, called from nuxt API
Middleware that sets the secretKey before API handler is ran
Works perfectly fine locally, doesn't when deployed (same error)

[nuxt] [request error] [unhandled] [500],You need to set the TRIGGER_SECRET_KEY environment variable. See https://trigger.dev/docs/management/overview#authentication
#

(Deployed on cloudflare through https://hub.nuxt.com/, but that doesn't change anything, it creates a normal cloudflare-pages app that works the same)

inner sonnet
#

Can you try logging the variable out when deployed?

strange escarp
#

Yep

#

HUH

#

Yeah it's empty

#

Just tried hard coding the key, works fine

#

Thanks, there seem to be an issue with any sub-prop of "trigger" proeprty in the runtime config of nuxt. So used to it being reliable I didn't check

#

thansk a lot, I should be able to debug this by myself

inner sonnet
#

I couldn’t figure out from the NuxtHub docs how to set a server side secret that wasn’t hard coded in Git 😵‍💫

#

Hope you get to sorted 👍