feat: include user_id in device-flow token response#141
Merged
tomasz-tomczyk merged 1 commit intomainfrom Apr 29, 2026
Merged
Conversation
The /api/device/token response now carries user_id alongside the existing user_name (and adds user_email). This lets the CLI cache the verified server-side user id at login time instead of needing to lazy-backfill it via /api/auth/whoami on first share — closing a window where the daemon sent shares with a blank user_id and the server wrote them as "imported". See also: tomasz-tomczyk/crit#391 (CLI side) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
7 tasks
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #141 +/- ##
==========================================
+ Coverage 77.21% 77.25% +0.03%
==========================================
Files 52 52
Lines 1567 1574 +7
==========================================
+ Hits 1210 1216 +6
- Misses 357 358 +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:
|
tomasz-tomczyk
added a commit
to tomasz-tomczyk/crit
that referenced
this pull request
Apr 29, 2026
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>
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
user_id,user_name,user_email(was:user_nameonly).Crit.DeviceCodes.poll_device_code/1returns{:ok, access_token, %{id, name, email}}instead of{:ok, access_token, user_name}.Why
Closes a prod attribution bug where
critCLI sent shares with blankuser_idon the comments — the server then wrote them withuser_id = nilandauthor_identity = "imported", even though the bearer token authenticated the request correctly. Withoutuser_idin this response, the CLI had no way to cache the verified id at login time.Review
Test plan
mix precommit— clean (471 tests, 0 failures)device_codes_test.exsanddevice_api_controller_test.exsupdated to assert the new shape./scripts/e2e-share.shfrom crit/) — all tests passSee also: tomasz-tomczyk/crit#393 (CLI side that consumes this)
🤖 Generated with Claude Code