fix: persist verified user_id on auth login#393
Merged
tomasz-tomczyk merged 1 commit intomainfrom Apr 29, 2026
Merged
Conversation
Two bugs surfaced from a prod attribution miss: 1. crit auth login wrote auth_user_name and auth_user_email but never auth_user_id, because the device-flow token response didn't carry it. The daemon then stamped comments with a blank user_id and the server wrote them as "imported". 2. The identity fields were saved one at a time, so a stale auth_user_id from a previous account survived a re-login as a different user. The payload then contained user A's id while the bearer token authenticated as user B; the server treated the mismatch as anonymous. Fix: - Add UserID to tokenResponse so the CLI reads the new field that tomasz-tomczyk/crit-web#141 emits. - Extract saveAuthIdentity() that rewrites all three identity fields atomically: missing fields delete the key on disk so a stale value cannot survive a re-login. - Belt-and-braces: when the response omits user_id (older crit-web), fall through to lazyBackfillAuthUserID() which fetches via whoami. Existing logged-in users need to log out + log in to pick up the verified user_id; comments authored before then stay anonymous on the server (intentional — the explicit re-login is the migration). Follow-up: consolidate the five overlapping author/identity config fields (#392). See also: tomasz-tomczyk/crit-web#141 (server side) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
5 tasks
Codecov Report❌ Patch coverage is
❌ Your patch status has failed because the patch coverage (66.66%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #393 +/- ##
==========================================
+ Coverage 66.53% 66.64% +0.10%
==========================================
Files 19 19
Lines 8197 8206 +9
==========================================
+ Hits 5454 5469 +15
+ Misses 2316 2311 -5
+ Partials 427 426 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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
Two attribution bugs surfaced from a prod miss where shared comments came back with
user_id = nilandauthor_identity = "imported"even though the user was logged in:crit auth loginnever savedauth_user_id— the device-flow token response only carriedaccess_token,user_name,user_email. The daemon then stamped comments with a blank user_id and the server wrote them as imported. Fixed in companion crit-web PR fix: add --author flag to all reply-to examples #141 (server now returnsuser_id); this PR consumes it.Stale identity survived re-login — the existing code wrote
auth_user_name/auth_user_emailone at a time, so when a user logged in as account B after previously using account A, A'sauth_user_id(and any field B's response omitted) stayed on disk. The payload then contained user A's id while the bearer token authenticated as user B; the server treated the mismatch as anonymous.Changes
UserIDtotokenResponse.saveAuthIdentity()that rewrites all three identity fields atomically: missing fields delete the key on disk so a stale value cannot survive a re-login.user_id(older crit-web), fall through tolazyBackfillAuthUserID()which fetches via whoami.Migration
Existing logged-in users need to log out + log in to pick up the verified
user_id. Comments authored before then stay anonymous on the server (intentional — the explicit re-login is the migration).Review
Test plan
gofmt -l .— cleangolangci-lint run ./...— 0 issuesgo test -race -count=1 ./...— cleanTestSaveAuthIdentity_OverwritesStaleFields(the prod regression),TestSaveAuthIdentity_RemovesFieldsAbsentFromResponse,TestPollDeviceToken_ParsesUserID./scripts/e2e-share.sh) — all tests passFollow-up: #392 (consolidate the five overlapping author/identity config fields).
See also: tomasz-tomczyk/crit-web#141 (server side)
🤖 Generated with Claude Code