#TRIGGER_SECRET_KEY not found when triggering task
1 messages · Page 1 of 1 (latest)
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));
};
We need to create a SvelteKit guide, it's on our list. Unfortunately I think SvelteKit doesn't read from process.env so you need to manually configure the SDK: https://trigger.dev/docs/apikeys#manually-configuring-the-sdk
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
});
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
Thanks! @night token useful when we create the guide