Skip to content

Hand an existing session to desktop sign-in instead of asking again - #5

Merged
mehfuzh merged 1 commit into
mainfrom
fix/desktop-login-handoff
Nov 9, 2026
Merged

mehfuzh merged 1 commit into
mainfrom
fix/desktop-login-handoff

Conversation

@mehfuzh

@mehfuzh mehfuzh commented Nov 9, 2026

Copy link
Copy Markdown
Member

Problem

docent's /login (and the desktop app) open /login?mode=desktop&port=…. Desktop mode always showed the sign-in form, even when the browser was already signed in to the dashboard: only the access token was kept, and the local agent needs a refresh token as well.

Change

  • Keep the refresh token in localStorage beside token at sign-in (email code, Google). Apple returns none, so nothing is kept for it.
  • In desktop mode, if a refresh token is stored, exchange it at /auth/jwt/refresh for a fresh pair and post it to the agent's /v1/auth/callback, landing on /redirect?mode=desktop, with no form. With no stored token, or a refused one, the form shows as before.
  • Logout (account menu, userService.logout) and a failed code entry clear the refresh token.
  • The hand-off to the agent, duplicated in the login and OAuth callback pages, moves to src/app/shared/desktop.ts.

Notes

  • Sessions from before this change have no refresh token, so they see the form once more.
  • tsc --noEmit passes; not yet exercised in a browser.

Test plan

  • Sign in on the dashboard, then /login in docent → no form, docent reports signed in
  • Log out on the dashboard, then /login → form shows
  • Safari: hand-off falls back to the GET callback

🤖 Generated with Claude Code

Opening /login?mode=desktop always showed the form, even when the browser
was already signed in, because only the access token was kept and the
desktop agent needs a refresh token too.

Keep the refresh token beside the access token at sign-in (email code and
OAuth), and in desktop mode exchange it for a fresh pair and post it to the
local agent's callback. Without one, or when the platform refuses it, the
form shows as before. Logging out clears it.

The desktop hand-off, duplicated in the login and OAuth callback pages, now
lives in shared/desktop.ts.
@mehfuzh
mehfuzh merged commit 6e1aafa into main Nov 9, 2026
1 check passed
@mehfuzh
mehfuzh deleted the fix/desktop-login-handoff branch November 9, 2026 04:55
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