Skip to content

fix(connection-form): show Username field for MongoDB and other optional-auth databases#1266

Merged
datlechin merged 1 commit into
mainfrom
fix/mongodb-username-field
May 14, 2026
Merged

fix(connection-form): show Username field for MongoDB and other optional-auth databases#1266
datlechin merged 1 commit into
mainfrom
fix/mongodb-username-field

Conversation

@datlechin

Copy link
Copy Markdown
Member

Problem

A MongoDB connection to an auth-enabled server connects "successfully" but the sidebar table list shows [13] Command listCollections requires authentication. Compass connects to the same server fine.

The connection form never showed a Username field for MongoDB, so the connection saved with an empty username.

Root cause

MongoDBPlugin declares requiresAuthentication = false (correct: local-dev MongoDB has no auth). But GeneralPaneView used that same flag to decide whether the Username field is visible. Those are different questions:

  • Is auth mandatory? — no, for MongoDB
  • Should the Username field exist? — yes, most real MongoDB servers need it

With the field hidden, the connection saved username = "". The driver's buildUri() guards credentials behind if !user.isEmpty, so the URI had no userinfo at all. connect() only runs {"ping": 1}, which MongoDB allows unauthenticated, so the connection looked healthy. The first real operation, listCollections for the table list, failed with MongoDB error code 13 (Unauthorized).

Fix

Gate the Username field on connectionMode == .network instead of requiresAuthentication. authenticationSection is only built for non-file-based connections, so the reachable modes are .network and .apiOnly. Every network database supports a username regardless of whether auth is enforced; .apiOnly connections authenticate through their own authFields and correctly keep it hidden.

Main-app only. No plugin change, no PluginKit ABI bump, no registry re-tag.

Notes

Two related issues found but left out of this PR:

  • The Database field is hidden for MongoDB by the same requiresAuthentication misuse. It doesn't cause this bug (MongoDB auto-discovers databases once authenticated).
  • MongoDBConnection.buildUri() silently drops a password when the username is empty. That's a plugin-side change; once this fix lands, it's only reachable by deliberately leaving Username blank.

Test plan

  • Create a MongoDB connection: the Username field is now visible
  • Enter credentials for an auth-enabled server, connect, confirm the table list loads
  • Confirm .apiOnly connections (DynamoDB, BigQuery) still hide the Username field
  • Confirm file-based connections (SQLite, CSV) are unaffected

@datlechin datlechin merged commit 8626034 into main May 14, 2026
@datlechin datlechin deleted the fix/mongodb-username-field branch May 14, 2026 16:04
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.

1 participant