Skip to content

fix: send credentials to the plugin endpoints so backend switching works - #122

Merged
fatherlinux merged 1 commit into
mainfrom
fix/122-plugin-endpoints-credentials
Aug 1, 2026
Merged

fix: send credentials to the plugin endpoints so backend switching works#122
fatherlinux merged 1 commit into
mainfrom
fix/122-plugin-endpoints-credentials

Conversation

@fatherlinux

Copy link
Copy Markdown
Member

Fixes the report that "the Google Drive checkbox is stuck on and the pCloud checkbox won't check."

Root cause — predates the pCloud plugin

The storage backend is a per-user choice the server resolves from the request credentials (spec 007). But every frontend call to /api/plugins and /api/plugins/toggle used a bare fetch() with no credentials attached, so the server could not tell who was asking:

  • GET /api/plugins fell back to DEFAULT_STORAGE_BACKENDJSON on Google Drive rendered active for everyone, regardless of their real choice.
  • POST /api/plugins/toggle returned 401 for any storage plugin, and togglePlugin silently reverted the checkbox → no storage backend could be selected from the UI at all.

Reproduced against production before the fix:

$ curl -s https://acquacotta.crunchtools.com/api/plugins | jq -r .active_storage
json-google-drive          # regardless of caller

$ curl -s -X POST .../api/plugins/toggle -d '{"plugin_id":"json-pcloud",...}'
{"error":"Not authenticated"}   HTTP 401

Switching to Sheets was equally broken. pCloud was just the first backend switch anyone attempted since spec 007 landed.

Fix

pluginFetch() in storage.js attaches credentials when present. Unlike authenticatedFetch it deliberately does not require a storage location — switching backends is precisely the moment the new backend has none yet — and it stays usable logged out, which the pre-login settings view renders. All 9 call sites converted.

Two UI fixes for the same report:

  • A failed toggle now reports why instead of silently snapping back. The silence is why this looked like "the checkbox won't check" rather than an error.
  • Toggling pCloud on now starts the OAuth link instead of recording a backend the browser has no token for. Linking is the switch — its callback already records the backend.

Testing

  • 4 new server tests pinning the contract: the list reports the caller's own backend, the toggle succeeds with credentials and 401s without, and one user's switch doesn't move another's.
  • 273 tests pass; ruff 0.16.1 check + format clean; node --check on storage.js.

Note the new tests pin the server contract, which was already correct — the defect was client-side. They guard against the endpoints silently losing per-user resolution, but the client wiring itself is verified by manual retest in production.

🤖 Generated with Claude Code

https://claude.ai/code/session_011RYAzzVJJqrsp6TkeRS4vX

The storage backend is a per-user choice resolved from the request
credentials (spec 007), but every frontend call to /api/plugins and
/api/plugins/toggle used a bare fetch() with no credentials attached. The
server therefore could not tell who was asking:

- GET /api/plugins fell back to DEFAULT_STORAGE_BACKEND, so JSON on Google
  Drive rendered as active for everyone regardless of their actual choice.
- POST /api/plugins/toggle returned 401 for any storage plugin, and
  togglePlugin silently reverted the checkbox — so no storage backend could
  be selected from the UI at all.

This predates the pCloud plugin; switching to Sheets was equally broken.
pCloud was simply the first backend switch attempted since spec 007.

Adds pluginFetch(), which attaches credentials when present. Unlike
authenticatedFetch it does not require a storage location — switching
backends is exactly the moment the new backend has none yet — and it stays
usable logged out, which the pre-login settings view needs.

Two UI fixes for the same report:

- A failed toggle now says why instead of silently snapping back.
- Toggling pCloud on now starts the OAuth link rather than recording a
  backend the browser has no token for. Linking is the switch; its callback
  already records the backend.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011RYAzzVJJqrsp6TkeRS4vX
@gemini-code-assist

Copy link
Copy Markdown

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Gatehouse found no issues.

@fatherlinux
fatherlinux merged commit f652a8f into main Aug 1, 2026
5 checks passed
@fatherlinux
fatherlinux deleted the fix/122-plugin-endpoints-credentials branch August 1, 2026 21:03
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