Skip to content

feat: prompt for API key when server requires authentication#48

Merged
ajainvivek merged 1 commit into
mainfrom
feat/api-key-auth-prompt
Mar 16, 2026
Merged

feat: prompt for API key when server requires authentication#48
ajainvivek merged 1 commit into
mainfrom
feat/api-key-auth-prompt

Conversation

@ajainvivek
Copy link
Copy Markdown
Contributor

Summary

  • Servers with auth enabled return 401/403 on unauthenticated requests. Previously the client silently failed or showed a generic connection error with no way to enter credentials.
  • This PR detects auth-required servers and surfaces a focused API key prompt dialog before completing the connection.

Changes

src/lib/api.ts

  • checkAuth() — probes /v1/tables without credentials; returns { authRequired: true } on 401/403, gracefully ignores network errors so it never blocks the connect flow
  • updateApiKey() — applies a key to an existing in-memory client instance after the prompt is confirmed

src/components/connection/ApiKeyPromptDialog.tsx (new)

  • Modal dialog with a password input, loading state, and inline error feedback
  • Validates the key by calling listTables() before completing — shows "Invalid API key" if the server rejects it

src/components/layout/Sidebar.tsx

  • handleConnect now probes for auth after a successful connection test
  • If auth is required: parks the client in a ref, sets pendingAuthConnection, shows the dialog
  • handleApiKeySubmit applies the key, calls listTables() to validate, then finalises setClient / setActiveConnection

src/App.tsx

  • On startup, if a persisted connection has no stored apiKey and the server now requires one, drops activeConnection back to null so the user lands on the connection list instead of a broken session

Test plan

  • Connect to a server with auth disabled — flow unchanged, no dialog shown
  • Connect to a server with auth enabled and no stored key — API key dialog appears
  • Enter a wrong key — "Invalid API key" error shown, dialog stays open
  • Enter the correct key — connects successfully
  • Restart the app with a previously connected auth-required server that has no stored key — redirected to connection list

Servers with auth enabled return 401/403 on unauthenticated requests.
Previously the client would silently fail or show a generic error.

- Add `checkAuth()` to ReasonDBClient — probes /v1/tables without auth
  and returns `{ authRequired: true }` on 401/403
- Add `updateApiKey()` to apply a key to an existing client instance
- Add ApiKeyPromptDialog — modal that validates the key by calling
  listTables() before completing the connection
- Wire into Sidebar.handleConnect: if the server requires auth, park the
  client and show the prompt instead of failing
- Wire into App startup: if a persisted connection has no stored key and
  the server now requires auth, drop it back to the connection list
@ajainvivek ajainvivek merged commit b2a523f into main Mar 16, 2026
2 checks passed
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