Add Lemon Squeezy environment variable schema validation and removed NODE_ENV from production variables, as it causes issues in Vercel

- Implement `getLemonSqueezyEnv` function to validate required environment variables for Lemon Squeezy integration using `zod`.
- Ensure `LEMON_SQUEEZY_SECRET_KEY`, `LEMON_SQUEEZY_SIGNING_SECRET`, and `LEMON_SQUEEZY_STORE_ID` are present and valid.
This commit is contained in:
gbuomprisco
2024-09-05 15:36:11 +02:00
parent 3e1c12fcbb
commit 117602ac5e
2 changed files with 21 additions and 6 deletions

View File

@@ -5,9 +5,6 @@
## AVOID PLACING SENSITIVE DATA IN THIS FILE.
## PUBLIC KEYS OR CONFIGURATION ARE OKAY TO BE PLACED HERE.
# NODE ENV
NODE_ENV=production
# SUPABASE
NEXT_PUBLIC_SUPABASE_URL=

View File

@@ -1,11 +1,29 @@
import { z } from 'zod';
/**
* @name getLemonSqueezyEnv
* @description Get the Lemon Squeezy environment variables.
* It will throw an error if any of the required variables are missing.
*/
export const getLemonSqueezyEnv = () =>
z
.object({
secretKey: z.string().min(1),
webhooksSecret: z.string().min(1),
storeId: z.string(),
secretKey: z
.string({
description: `The secret key you created for your store. Please use the variable LEMON_SQUEEZY_SECRET_KEY to set it.`,
})
.min(1),
webhooksSecret: z
.string({
description: `The shared secret you created for your webhook. Please use the variable LEMON_SQUEEZY_SIGNING_SECRET to set it.`,
})
.min(1)
.max(40),
storeId: z
.string({
description: `The ID of your store. Please use the variable LEMON_SQUEEZY_STORE_ID to set it.`,
})
.min(1),
})
.parse({
secretKey: process.env.LEMON_SQUEEZY_SECRET_KEY,