Skip to content

Commit 30f2694

Browse files
authored
allow usage without FLAGS_SECRET (#25)
1 parent 03ff044 commit 30f2694

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

packages/flags/src/lib/verify-access.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ export const verifyAccess = trace(
3030
secret: string | undefined = process?.env?.FLAGS_SECRET,
3131
) {
3232
if (!authHeader) return false;
33+
if (!secret)
34+
throw new Error(
35+
'@vercel/flags: verifyAccess was called without a secret. Please set FLAGS_SECRET environment variable.',
36+
);
37+
3338
const data = await decrypt<{}>(
3439
authHeader?.replace(/^Bearer /i, ''),
3540
secret,

packages/flags/src/next/index.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -379,13 +379,6 @@ export function flag<
379379

380380
const flag = trace(
381381
async (...args: any[]) => {
382-
// defining flags throws since a FLAGS_SECRET is necessary for encrypting the flag code
383-
if (!process.env.FLAGS_SECRET) {
384-
throw new Error(
385-
'@vercel/flags: Missing FLAGS_SECRET env var. Will not respect any overrides until this secret is added as an environment variable.',
386-
);
387-
}
388-
389382
// Default method, may be overwritten by `getPrecomputed` or `run`
390383
// which is why we must not trace them directly in here,
391384
// as the attribute should be part of the `flag` function.

packages/flags/src/next/precompute.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,12 @@ export async function getPrecomputed<T extends JsonValue>(
133133
code: string,
134134
secret: string | undefined = process.env.FLAGS_SECRET,
135135
): Promise<any> {
136+
if (!secret) {
137+
throw new Error(
138+
'@vercel/flags: getPrecomputed was called without a secret. Please set FLAGS_SECRET environment variable.',
139+
);
140+
}
141+
136142
const flagSet = await deserialize(precomputeFlags, code, secret);
137143

138144
if (Array.isArray(flagOrFlags)) {
@@ -162,6 +168,12 @@ export async function generatePermutations(
162168
filter: ((permutation: Record<string, JsonValue>) => boolean) | null = null,
163169
secret: string = process.env.FLAGS_SECRET!,
164170
): Promise<string[]> {
171+
if (!secret) {
172+
throw new Error(
173+
'@vercel/flags: generatePermutations was called without a secret. Please set FLAGS_SECRET environment variable.',
174+
);
175+
}
176+
165177
const options = flags.map((flag) => {
166178
// no permutations if you don't declare any options
167179
if (!flag.options) return [];

0 commit comments

Comments
 (0)