File tree Expand file tree Collapse file tree 3 files changed +17
-7
lines changed Expand file tree Collapse file tree 3 files changed +17
-7
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,11 @@ export const verifyAccess = trace(
30
30
secret : string | undefined = process ?. env ?. FLAGS_SECRET ,
31
31
) {
32
32
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
+
33
38
const data = await decrypt < { } > (
34
39
authHeader ?. replace ( / ^ B e a r e r / i, '' ) ,
35
40
secret ,
Original file line number Diff line number Diff line change @@ -379,13 +379,6 @@ export function flag<
379
379
380
380
const flag = trace (
381
381
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
-
389
382
// Default method, may be overwritten by `getPrecomputed` or `run`
390
383
// which is why we must not trace them directly in here,
391
384
// as the attribute should be part of the `flag` function.
Original file line number Diff line number Diff line change @@ -133,6 +133,12 @@ export async function getPrecomputed<T extends JsonValue>(
133
133
code : string ,
134
134
secret : string | undefined = process . env . FLAGS_SECRET ,
135
135
) : 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
+
136
142
const flagSet = await deserialize ( precomputeFlags , code , secret ) ;
137
143
138
144
if ( Array . isArray ( flagOrFlags ) ) {
@@ -162,6 +168,12 @@ export async function generatePermutations(
162
168
filter : ( ( permutation : Record < string , JsonValue > ) => boolean ) | null = null ,
163
169
secret : string = process . env . FLAGS_SECRET ! ,
164
170
) : 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
+
165
177
const options = flags . map ( ( flag ) => {
166
178
// no permutations if you don't declare any options
167
179
if ( ! flag . options ) return [ ] ;
You can’t perform that action at this time.
0 commit comments