Skip to content

feat: sign in with a ChatGPT account, and spend reset credits on request - #40

Merged
fylorn merged 1 commit into
devfrom
feat/chatgpt-login
Sep 17, 2026
Merged

fylorn merged 1 commit into
devfrom
feat/chatgpt-login

Conversation

@fylorn

@fylorn fylorn commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Phase 4 of the ChatGPT account work, the desktop half. It pins core v0.5.0, whose control plane runs the login (Core#38).

Signing in

  • Service type in the new-upstream dialog offers ChatGPT 账号(登录). Choosing it opens a login dialog instead of the form, because a login fills in the address, the protocol and the credentials by itself.
  • The dialog states the risks before anything happens: the subscription is meant for OpenAI's own clients, requests identify honestly as ThinkWatch, the credentials live in the local config file, and deleting the upstream revokes them. The button stays disabled until that has been acknowledged.
  • A name and an egress proxy are chosen up front — sign-in and every later request go out the same way, and a user who needs a proxy to reach OpenAI needs it here first.
  • The browser opens, core waits for the callback, and the dialog settles on the login_finished event. Polling every two seconds is the fallback for a missed event.

Coming back to the app

  • thinkwatch:// is registered, so the page the browser lands on can bring the app back to the front. The window is recreated when it was closed, which is the normal state for a menu-bar app.
  • The authorize URL stays on the Rust side. The webview asks to reopen this login by id, so there is no path where the interface hands the app an arbitrary URL to open.

Quota and reset credits

  • A ChatGPT account row has a 额度与重置卡… action: the quota windows with their reset times, and the reset credits.
  • A credit cannot be refunded, so one is spent only after an explicit confirmation, with an idempotency key, and never by the gateway on its own. The confirmation also says what happens when no window needs resetting: the backend returns without spending one.

Test plan

  • pnpm typecheck, pnpm build, pnpm test (88)
  • cargo fmt --check, cargo clippy --all-targets -- -D warnings, cargo test (77)
  • Walked both dialogs in the isolated preview against a mocked control plane: the consent gate, the waiting state, the result, the new row in the table, the quota windows, the confirmation, and spending a credit.
  • Two defects that walk-through caught and this branch fixes: a checkbox wrapped in a label toggled twice and could not be ticked, and an unmount flag that stayed set after React's development double-invoke, so the login result never reached the dialog.
  • Not exercised here: the deep link needs a bundled app, so it is verified in a build rather than in tauri dev.

🤖 Generated with Claude Code

Pins core v0.5.0, whose control plane runs the login.

- "Service type" in the new-upstream dialog offers a ChatGPT account. It
  opens a login dialog: the risks first, then a name and an egress proxy,
  then the browser. core waits for the callback and writes the upstream,
  and the dialog settles on the login event with polling as a fallback.
- The app registers thinkwatch://, so the page the browser lands on can
  bring the app back to the front, recreating the window when it was
  closed. The authorize URL stays on the Rust side: the webview never
  hands the app a URL to open.
- A ChatGPT account has a "Quota and reset credits" dialog: the windows
  with their reset times, and the credits with an explicit confirmation
  before one is spent. A credit cannot be refunded, so it is only ever
  spent when asked for, with an idempotency key, and never by the gateway.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@fylorn
fylorn merged commit 5e66cce into dev Sep 17, 2026
2 checks passed
@fylorn
fylorn deleted the feat/chatgpt-login branch September 17, 2026 18:43
@fylorn fylorn mentioned this pull request Sep 18, 2026
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