fix(stripe): correct Stripe secret environment variable typo#5
Draft
Yuankai619 wants to merge 1 commit into
Draft
fix(stripe): correct Stripe secret environment variable typo#5Yuankai619 wants to merge 1 commit into
Yuankai619 wants to merge 1 commit into
Conversation
The Stripe initialization and mock key check were using process.env.Stripe_CHANEL_SECRET instead of process.env.Stripe_CHANNEL_SECRET. This spelling error caused the Stripe client to fail initialization with 'Neither apiKey nor config.authenticator provided' errors at runtime because the correct environment variable name deployed on Cloud Run contains two 'L's (Stripe_CHANNEL_SECRET). This commit corrects the spelling in both files. 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 Stripe_CHANNEL_SECRET across the payment route and Stripe library. The reviewer suggests improving the error handling in lib/stripe.ts by replacing the non-null assertion with an explicit check and a descriptive error message to prevent cryptic runtime errors if the environment variable is missing.
| 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.
While correcting the typo is necessary, relying on a non-null assertion (!) for environment variables can lead to cryptic runtime errors if the variable is missing. Adding an explicit check ensures a clearer error message, which would have helped identify the issue described in the PR more quickly.
Suggested change
| 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'); | |
| } |
References
- Ensure appropriate null/nil/None checks or other language-idiomatic guards exist before object property accesses or using values that are expected to be present.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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).