fix: treat already-handled device authorization as success#90
Merged
Conversation
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
yahyafakhroji
approved these changes
Jun 24, 2026
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
Running
datumctl login --no-browsersucceeds, 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
/signedinpage completes the device flow inside a Server Component render by callingcompleteDeviceAuthorization. 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-browserflow (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 withFAILED_PRECONDITIONbecause 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 inidp/[provider]/success/page.tsx, which handles its one-time intent consumption the same way.Test plan
datumctl login --no-browserin prod completes without showing the error alert on/signedindatumctl login(auto-browser) still completes normallyCloses #89