File size: 521 Bytes
97ee7cb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/**
 * Read a required environment variable, throwing a clear error if missing.
 * MUST be called inside function handlers, never at module scope.
 *
 * @example
 * ```ts
 * const apiKey = requireEnv("DODO_API_KEY");
 * ```
 */
export function requireEnv(name: string): string {
  const value = process.env[name];
  if (!value) {
    throw new Error(
      `Missing required environment variable: ${name}. ` +
        `Set it in the Convex dashboard under Settings > Environment Variables.`,
    );
  }
  return value;
}