[PR #362] [MERGED] fix(connections): clear API key when switching to Claude (Subscription) #4577

Closed
opened 2026-10-22 04:08:52 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/362
Author: @LukaTheHero
Created: 5/3/2026
Status: ✅ Merged
Merged: 5/3/2026
Merged by: @LukaTheHero

Base: main ← Head: fix/claude-subscription-clear-api-key


📝 Commits (1)

  • ddc4795 fix(connections): clear API key when switching to Claude (Subscription)

📊 Changes

1 file changed (+6 additions, -0 deletions)

View changed files

📝 packages/client/src/components/connections/ConnectionEditor.tsx (+6 -0)

📄 Description

Summary

Reported by SILCORE (Discord, v1.5.6, WSL2 Ubuntu 24.04 / Windows 11):

If any character is present in the API Key field of the connections input before you select "Claude (Subscription)", although the selection locks the API Key field from being edited further, those character(s) cause the connection to fail.

Reproduction

  1. Create a new connection of type Anthropic
  2. Type any API key (e.g. abc123)
  3. Change the connection type to Claude (Subscription)
  4. Click Send Test Message
  5. Connection fails

Root cause

In ConnectionEditor.tsx, the provider button onClick already auto-fills the base URL and clears the model when switching providers, but it never touches localApiKey. The <input> for API key gets disabled for claude_subscription, which hides the value visually but the React state still holds whatever was typed. On save, if (localApiKey) payload.apiKey = localApiKey ships the leftover string to the server, and Test Message saves first if dirty — so the stale key is what gets used.

Fix

When the switched-to provider is claude_subscription, also call setLocalApiKey(""). Matches the reporter's expected behavior: empty the field before locking + hiding it. No server-side changes needed; the existing payload guard skips apiKey when it is falsy.

Files changed

  • packages/client/src/components/connections/ConnectionEditor.tsx — 6 lines, inside the provider button onClick.

Test plan (manual — please verify)

  • Reproduction case: New connection -> Anthropic -> key abc123 -> switch to Claude (Subscription) -> API Key field shows empty (still locked) -> Send Test Message succeeds
  • Reverse switch: Claude (Subscription) -> Anthropic -> API Key field is empty and editable again
  • Existing-connection regression: Open an Anthropic connection that already has a saved key on the server -> switch to Claude (Subscription) -> Save -> switch back to Anthropic -> original saved key on the server is still intact (we never sent a clear, just suppressed the send)

Summary by CodeRabbit

  • Bug Fixes
    • Fixed an issue where previously entered API keys would persist when switching between connection providers, ensuring a clean state for each provider.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/362 **Author:** [@LukaTheHero](https://github.com/LukaTheHero) **Created:** 5/3/2026 **Status:** ✅ Merged **Merged:** 5/3/2026 **Merged by:** [@LukaTheHero](https://github.com/LukaTheHero) **Base:** `main` ← **Head:** `fix/claude-subscription-clear-api-key` --- ### 📝 Commits (1) - [`ddc4795`](https://github.com/Pasta-Devs/Marinara-Engine/commit/ddc4795fa5228f468f6fb3527a5ec81bc8c33ead) fix(connections): clear API key when switching to Claude (Subscription) ### 📊 Changes **1 file changed** (+6 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `packages/client/src/components/connections/ConnectionEditor.tsx` (+6 -0) </details> ### 📄 Description ## Summary Reported by **SILCORE** (Discord, v1.5.6, WSL2 Ubuntu 24.04 / Windows 11): > If any character is present in the API Key field of the connections input before you select "Claude (Subscription)", although the selection locks the API Key field from being edited further, those character(s) cause the connection to fail. ### Reproduction 1. Create a new connection of type **Anthropic** 2. Type any API key (e.g. `abc123`) 3. Change the connection type to **Claude (Subscription)** 4. Click **Send Test Message** 5. Connection fails ### Root cause In `ConnectionEditor.tsx`, the provider button `onClick` already auto-fills the base URL and clears the model when switching providers, but it never touches `localApiKey`. The `<input>` for API key gets `disabled` for `claude_subscription`, which hides the value visually but the React state still holds whatever was typed. On save, `if (localApiKey) payload.apiKey = localApiKey` ships the leftover string to the server, and Test Message saves first if dirty — so the stale key is what gets used. ### Fix When the switched-to provider is `claude_subscription`, also call `setLocalApiKey("")`. Matches the reporter's expected behavior: empty the field before locking + hiding it. No server-side changes needed; the existing payload guard skips `apiKey` when it is falsy. ## Files changed - `packages/client/src/components/connections/ConnectionEditor.tsx` — 6 lines, inside the provider button `onClick`. ## Test plan (manual — please verify) - [x] Reproduction case: New connection -> Anthropic -> key `abc123` -> switch to Claude (Subscription) -> API Key field shows empty (still locked) -> **Send Test Message** succeeds - [x] Reverse switch: Claude (Subscription) -> Anthropic -> API Key field is empty and editable again - [x] Existing-connection regression: Open an Anthropic connection that already has a saved key on the server -> switch to Claude (Subscription) -> Save -> switch back to Anthropic -> original saved key on the server is still intact (we never sent a clear, just suppressed the send) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Fixed an issue where previously entered API keys would persist when switching between connection providers, ensuring a clean state for each provider. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:08:52 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#4577
No description provided.