Skip to content

Conversation

@evnchn
Copy link
Collaborator

@evnchn evnchn commented Feb 2, 2026

Motivation

Fixes #2578, which boils down to how ui.run_with() absolutely does not play well with parent FastAPI app's SessionMiddleware

Implementation

When using ui.run_with() with a parent FastAPI app that already has SessionMiddleware installed, NiceGUI now:

  • Inherits the secret if no storage_secret is provided or if the same secret is given (fixes case where storage silently failed)
  • Detects conflicts when different secrets are used with the same cookie name, and automatically renames NiceGUI's cookie to avoid silent failures, with a warning guiding the user

Progress

  • I chose a meaningful title that completes the sentence: "If applied, this PR will..."
  • The implementation is complete.
  • If this PR addresses a security issue, it has been coordinated via the security advisory process.
  • Running with a FastAPI instance is not-in-scope for the Pytest
  • Docstring will be self-explanatory and serve as documentation. But it does not show in https://nicegui.io though.

When using ui.run_with() with a parent FastAPI app that already has
SessionMiddleware installed, NiceGUI now:

- Inherits the secret if no storage_secret is provided or if the same
  secret is given (fixes case where storage silently failed)
- Detects conflicts when different secrets are used with the same cookie
  name, and automatically renames NiceGUI's cookie to avoid silent
  failures, with a warning guiding the user

Fixes zauberzeug#2578

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@evnchn evnchn added the bug Type/scope: Incorrect behavior in existing functionality label Feb 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Type/scope: Incorrect behavior in existing functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Attaching to a FastAPI instance with another storage_secret breaks session storage

1 participant