#TRIGGER_SECRET_KEY not found when triggering task

1 messages · Page 1 of 1 (latest)

cloud dove
#

I managed to setup self hosted trigger.dev, however in my SvelteKit app on an api route when I want to trigger task i get error: ""You need to set the TRIGGER_SECRET_KEY environment variable.""

The env variables are set in .env, so it must be something silly on my part. Help would be appreciated :D

#

Forgot to paste the +server.ts:
import type { pleaseTestTask } from '$trigger/test-task';
import { tasks } from '@trigger.dev/sdk/v3';
import type { RequestHandler } from './$types';

export const GET: RequestHandler = async () => {
const handle = await tasks.trigger<typeof pleaseTestTask>(
'test-task',
'Test'
);
return new Response(JSON.stringify(handle));
};

hidden bane
#

So I think somewhere in your backend, in a file that is definitely executed, you need to:

import { configure } from "@trigger.dev/sdk/v3";
import { TRIGGER_SECRET_KEY } from '$env/static/private';

configure({
  secretKey: TRIGGER_SECRET_KEY,
  baseURL: "https://mytrigger.example.com", // your URL
});
cloud dove
#

Thanks for help and link, I have managed to get it to work.
For others looking for a solution, in short I added extra function in my hooks.server.ts and placed this function there:

// imports
import { configure } from "@trigger.dev/sdk/v3";
import { TRIGGER_SECRET_KEY } from '$env/static/private';

// Configure trigger.dev enviroment variables
const configureTriggerDev: Handle = async ({ event, resolve }) => {
    configure({
        secretKey: TRIGGER_SECRET_KEY,
        baseURL: TRIGGER_API_URL
    });
    const response = await resolve(event);
    return response;
};

Then add this to the sequence(), next to other functions if you have them.
Make sure to start the SvelteKit app, check if its running and then proceed to launch "trigger.dev@latest dev". I am looking forward to SvelteKit guide. Cheers

hidden bane
#

Thanks! @night token useful when we create the guide