feat: auto-fetch ngrok tunnel credentials from SyftHub#97
Merged
Conversation
Instead of requiring users to manually paste an ngrok developer token during onboarding and in settings, fetch tunnel credentials automatically from SyftHub's GET /api/v1/users/me/tunnel-credentials endpoint. Backend: - Add get_tunnel_credentials() to SyftHubClient - configure_proxy handler now fetches credentials from SyftHub - proxy_service.connect() accepts domain directly (remove NGROK_DOMAIN_FORMAT) - Remove ProxyConfigRequest schema and request body from POST /settings/proxy Frontend: - Remove developer token input from onboarding and settings pages - configureProxy() sends POST with no body - Add Connect/Reconnect button to settings proxy status panel
…ct, remove manual connect button - Add Alembic migration to rename ngrok_username column to ngrok_domain - Update Settings entity and repository to use ngrok_domain - Add credentials-provider fallback to _reconnect_loop for self-healing at runtime (fetches fresh creds from SyftHub on first reconnect failure) - Remove Connect/Reconnect button from SettingsPage (fully automatic)
… unintended auto-reconnect - Rename connect(token, domain) to _connect() (internal), promote connect_with_fallback() to connect() as the public API - Handler's configure_proxy() delegates to proxy_service.connect() instead of duplicating the stored→fresh credentials fallback - Catch SyftHubError separately in handler to preserve status codes (e.g. 401) so frontend auth guard can trigger re-auth flow - Skip auto-connect on startup when no stored token exists, preventing override of explicit disconnect or custom URL mode - Fix Settings Save button: check !connected instead of !hasToken so disconnected tunnels can be re-triggered
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Since syft-space already authenticates with SyftHub during onboarding (register/login), we can leverage that session to fetch ngrok tunnel credentials automatically — removing the manual developer token input entirely and making the tunnel fully self-healing.
What changed:
get_tunnel_credentials()method that callsGET /api/v1/users/me/tunnel-credentialsto fetch a fresh(auth_token, domain)pairconnect()is now the single public API — tries stored credentials from DB first, falls back to fetching fresh ones from SyftHub via aCredentialsProvidercallback_connect(token, domain)is the internal method for explicit credentials_reconnect_loopis self-healing: on first reconnect failure per cycle, fetches fresh credentials from SyftHub, persists them, and retries immediately before exponential backoffconfigure_proxy()delegates toproxy_service.connect()— no duplicated credential fallback logic.SyftHubErrorstatus codes (e.g. 401) are preserved so the frontend auth guard can trigger re-authenticationngrok_usernamecolumn tongrok_domain(old username values are incompatible with the new flow where SyftHub returns the full domain)configureProxy()when switching to subdomain mode while disconnectedTest plan
ngrok_usernamein DB): migration drops it, startup sees stored token but no domain → fetches fresh credentials from SyftHub → tunnel connectsconfigureProxy()called → tunnel connectsconfigureProxy()returns 401 → frontend triggers re-auth flow