Skip to content

Commit d0fa045

Browse files
committed
Removed code block and updated title
1 parent 21d41f2 commit d0fa045

File tree

1 file changed

+11
-46
lines changed

1 file changed

+11
-46
lines changed

docs/guides/examples/vercel-sync-env-vars.mdx

Lines changed: 11 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: "Syncing environment variables from your Vercel projects"
3-
sidebarTitle: "Syncing Vercel env vars"
3+
sidebarTitle: "Vercel sync environment variables"
44
description: "This example demonstrates how to sync environment variables from your Vercel project to Trigger.dev."
55
---
66

@@ -12,60 +12,25 @@ This example shows how to automatically sync environment variables from your Ver
1212

1313
## Build configuration
1414

15-
To sync environment variables from your Vercel project to Trigger.dev, you'll first need to add this build configuration to your `trigger.config.ts` file. This extension will then automatically run every time you deploy your project.
15+
To sync environment variables from your Vercel project to Trigger.dev, you just need to add this build configuration to your `trigger.config.ts` file. This extension will then automatically run every time you deploy your project.
1616

1717
This code syncs encrypted environment variables, filtering them based on the current environment (production, preview, or development).
1818

19+
<Note>
20+
You need to set the `VERCEL_ACCESS_TOKEN` and `VERCEL_PROJECT_ID` environment variables, or pass
21+
in the token and project ID as arguments to the `vercelSyncEnvVars` build extension.
22+
</Note>
23+
1924
```ts trigger.config.ts
2025
import { defineConfig } from "@trigger.dev/sdk/v3";
2126
import { vercelSyncEnvVars } from "@trigger.dev/build/extensions/vercelSyncEnvVars";
2227

2328
export default defineConfig({
29+
project: "<project ref>",
30+
// Your other config settings...
2431
build: {
25-
extensions:
26-
extensions: [
27-
syncVercelEnvVars(),
28-
syncEnvVars(async (ctx) => {
29-
const environmentMap = {
30-
// Account for the different environment names used by Vercel
31-
prod: "production",
32-
staging: "preview",
33-
dev: "development",
34-
} as const;
35-
36-
const vercelEnvironment =
37-
environmentMap[ctx.environment as keyof typeof environmentMap];
38-
39-
const vercelApiUrl =
40-
`https://api.vercel.com/v8/projects/${process.env.VERCEL_PROJECT_ID}/env?decrypt=true`;
41-
42-
const response = await fetch(vercelApiUrl, {
43-
headers: {
44-
Authorization: `Bearer ${process.env.VERCEL_ACCESS_TOKEN}`,
45-
},
46-
});
47-
48-
if (!response.ok) {
49-
throw new Error(`HTTP error! status: ${response.status}`);
50-
}
51-
52-
const data = await response.json();
53-
54-
const filteredEnvs = data.envs
55-
.filter(
56-
(env: { type: string; value: string; target: string[] }) =>
57-
env.type === "encrypted" &&
58-
env.value &&
59-
env.target.includes(vercelEnvironment),
60-
)
61-
.map((env: { key: string; value: string }) => ({
62-
name: env.key,
63-
value: env.value,
64-
}));
65-
66-
return filteredEnvs;
67-
}),
68-
],,
32+
// Add the vercelSyncEnvVars build extension
33+
extensions: [vercelSyncEnvVars()],
6934
},
7035
});
7136
```

0 commit comments

Comments
 (0)