fix(stripe): correct Stripe secret environment variable typo#7
fix(stripe): correct Stripe secret environment variable typo#7Yuankai619 wants to merge 1 commit into
Conversation
The application was using Stripe_CHANEL_SECRET to fetch the Stripe API secret key, resulting in undefined when trying to instantiate the Stripe client. Correcting the environment variable to Stripe_CHANNEL_SECRET resolves the issue by matching the actual env var configured in Cloud Run. Co-Authored-By: Corvo Agent <noreply@corvo.dev>
There was a problem hiding this comment.
Code Review
This pull request corrects a typo in the environment variable name, changing Stripe_CHANEL_SECRET to Stripe_CHANNEL_SECRET in both the payment API route and the Stripe utility library. The reviewer recommended adding explicit validation for this environment variable in lib/stripe.ts to throw a clear error if it is missing, which improves robustness and simplifies debugging.
| export function getStripe(): Stripe { | ||
| if (!_stripe) { | ||
| const stripeSecretKey = process.env.Stripe_CHANEL_SECRET; | ||
| const stripeSecretKey = process.env.Stripe_CHANNEL_SECRET; |
There was a problem hiding this comment.
To improve robustness and follow defensive programming practices, we should explicitly validate that the Stripe_CHANNEL_SECRET environment variable is defined. Throwing a clear error early makes debugging configuration issues much easier than letting the Stripe client fail with a generic initialization error.
| const stripeSecretKey = process.env.Stripe_CHANNEL_SECRET; | |
| const stripeSecretKey = process.env.Stripe_CHANNEL_SECRET; | |
| if (!stripeSecretKey) { | |
| throw new Error('Missing Stripe_CHANNEL_SECRET environment variable'); | |
| } |
What does this PR do?
This PR corrects a spelling typo in the Stripe API secret key environment variable name. It changes
process.env.Stripe_CHANEL_SECRET(with one 'L') toprocess.env.Stripe_CHANNEL_SECRET(with two 'L's) in both the Stripe client helper initialization (lib/stripe.ts) and the mock key check inside the payment API endpoint (app/api/checkout/payment/route.ts).Why is this change needed?
At runtime, the Stripe initialization failed with the error
Neither apiKey nor config.authenticator providedbecause the deployed environment variable on Cloud Run is namedStripe_CHANNEL_SECRET. Since the code was looking forStripe_CHANEL_SECRET, it receivedundefined, causing the Stripe client instantiation to fail.Stripe_CHANEL_SECRET(should beStripe_CHANNEL_SECRET) resulting in a failure to initialize Stripe client.How was this change tested?
.env.production.exampleand deployment pipeline configs.What should reviewers focus on?
Reviewers should verify that the correct environment variable name on other deployment targets or local
.envis indeedStripe_CHANNEL_SECRETto ensure compatibility.Out of scope
No structural changes or payment logic changes were introduced.
Generated by
🤖 Corvo Agent — investigation traced to commit
750e214e131e5d5547d15c51b7c11981840f1a52e5e63293ef14b458aadeac24a0ac83f8f1737ce87a801368bf0bbe0cf8a18684d3ecad9532a9bbd53d62fc1ae51cd07f2bc403426c8f2026b9ebc0e6aa5bf00(which introduced theStripe_CHANEL_SECRETspelling).