Skip to content

fix: handle empty publicStripeKey to prevent frontend crash (#5640) Additional changes#5641

Open
iroussos25 wants to merge 7 commits intoNangoHQ:masterfrom
iroussos25:fix/stripe-public-key-null-check
Open

fix: handle empty publicStripeKey to prevent frontend crash (#5640) Additional changes#5641
iroussos25 wants to merge 7 commits intoNangoHQ:masterfrom
iroussos25:fix/stripe-public-key-null-check

Conversation

@iroussos25
Copy link
Copy Markdown

@iroussos25 iroussos25 commented Mar 15, 2026

The Problem
Self-hosted instances were experiencing hard process exits during both the frontend hydration and backend initialization phases. This was caused by the unsafe use of non-null assertions (!) and the Stripe SDK attempting to initialize with empty strings or undefined values when environment variables were missing.

The Fix
I have implemented a defense-in-depth approach to ensure Nango remains stable even if Stripe credentials are not provided.

Key Changes:

Backend (Runtime Guard): Replaced unsafe non-null assertions in the Stripe service. The backend now performs a runtime check for STRIPE_SECRET_KEY before instantiation, preventing unhandled exceptions that lead to container crash-loops.

Frontend (SDK Guard): Updated the Webapp utility to conditionally load the Stripe SDK only when a valid publishable key is present. If missing, the promise resolves to null gracefully.

Environment Sanitization: Modified getEnvJs and the WindowEnv interface to sanitize empty environment strings to undefined, providing a predictable data flow for configuration.

UI Resilience: Added a defensive check in the billing upgrade flow to handle "Stripe Unavailable" states, ensuring the user is met with a handled UI state rather than a blank screen/crash.

Scope Note
This PR is strictly focused on environment handling and Stripe stability. It does not include unrelated workspace configuration changes.

Closes #5640

P.S. I’ve recently applied for the Software Engineering role (Giannis Roussos). While setting up my local environment and diving into the docs, I noticed this friction point for self-hosted users and figured a PR was the best way to introduce my engineering style to the team.


This PR adds guards around Stripe initialization and usage to prevent crashes when Stripe environment variables are missing in self-hosted deployments. It replaces a non-null assertion with a runtime check on the backend, conditionally loads the Stripe SDK on the frontend, and updates the environment payload typing to allow undefined Stripe keys.

It also adds a UI-level fallback in the billing upgrade flow to show an error toast when Stripe is unavailable instead of proceeding with a null Stripe instance.


This summary was automatically generated by @propel-code-bot

Copy link
Copy Markdown
Contributor

@propel-code-bot propel-code-bot bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review found no issues; changes appear appropriate and stable.

Status: No Issues Found | Risk: Low

Review Details

📁 5 files reviewed | 💬 0 comments

Instruction Files
└── .claude/
    ├── agents/
    │   └── nango-docs-migrator.md
    └── skills/
        ├── agent-builder-skill/
        │   ├── EXAMPLES.md
        │   └── SKILL.md
        ├── creating-integration-docs/
        │   └── SKILL.md
        └── creating-skills-skill/
            └── SKILL.md

@iroussos25 iroussos25 changed the title fix: handle empty publicStripeKey to prevent frontend crash (#5640) fix: handle empty publicStripeKey to prevent frontend crash (#5640) Additional changes Mar 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

publicStripeKey: "" crash in env.js for self-hosted instances.

1 participant