Skip to content

fix: treat already-handled device authorization as success#90

Merged
mattdjenkinson merged 1 commit into
mainfrom
fix/device-auth-already-handled
Jun 25, 2026
Merged

fix: treat already-handled device authorization as success#90
mattdjenkinson merged 1 commit into
mainfrom
fix/device-auth-already-handled

Conversation

@mattdjenkinson

Copy link
Copy Markdown
Collaborator

Summary

Running datumctl login --no-browser succeeds, but the browser still shows a red error: Device Authorization Request has already been handled (COMMAND-D30Jf). The login works, so the error is confusing and looks like a failure.

The cause is that the /signedin page completes the device flow inside a Server Component render by calling completeDeviceAuthorization. The App Router does not guarantee a render runs exactly once per navigation. It can re-evaluate the page on an RSC refetch, prefetch, refresh, or retry, and the manual --no-browser flow (where the verification URL is pasted into a browser) makes a second hit more likely. The first call authorizes the grant and finishes the CLI login. A second call then fails with FAILED_PRECONDITION because the request was already handled, and that error gets rendered as an alert.

This makes the completion idempotent: if the call fails with FAILED_PRECONDITION (code 9), we treat it as success rather than throwing. The grant already succeeded on the first call, so there is nothing to recover. This matches the existing pattern in idp/[provider]/success/page.tsx, which handles its one-time intent consumption the same way.

Test plan

  • datumctl login --no-browser in prod completes without showing the error alert on /signedin
  • datumctl login (auto-browser) still completes normally
  • Denying consent on the device screen still works (it routes through the same server action)
  • A genuine non-precondition failure still surfaces an error

Closes #89

The /signedin page completes the device authorization flow during a
Server Component render, which the App Router can evaluate more than
once per navigation. The first call authorizes the grant; subsequent
calls fail with FAILED_PRECONDITION ("Device Authorization Request has
already been handled") and surfaced a spurious error even though login
succeeded. Treat that error code as success so the flow is idempotent.

Closes #89
@mattdjenkinson mattdjenkinson marked this pull request as ready for review June 24, 2026 16:00
@mattdjenkinson mattdjenkinson merged commit b1fc0ff into main Jun 25, 2026
6 checks passed
@mattdjenkinson mattdjenkinson deleted the fix/device-auth-already-handled branch June 25, 2026 08:51
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.

Device Authorization Request has already been handled

2 participants