Skip to content

feat(identify): send user data to identify after oauth flow#228

Open
LorrisSaintGenez wants to merge 2 commits into
mainfrom
feat/track-authenticated-user
Open

feat(identify): send user data to identify after oauth flow#228
LorrisSaintGenez wants to merge 2 commits into
mainfrom
feat/track-authenticated-user

Conversation

@LorrisSaintGenez
Copy link
Copy Markdown
Contributor

@LorrisSaintGenez LorrisSaintGenez commented Jun 2, 2026

What

Persist the authenticated user's identity alongside the OAuth tokens so CLI telemetry can attribute events to the logged-in user.

  • Store identity in the token. StoredToken now carries user_id/email/name, populated by SaveToken from the OAuth response's user object (same keychain entry — identity is bound to the token, not a profile).
  • Expose via LoadToken. Any caller reads identity straight off the stored token.
  • Send to Segment. root.go populates CLIAnalyticsEventMetadata from the stored token before Identify/Track. When authenticated, both carry userId (alongside anonymousId, so the first event aliases anonymous→user); email/name go on Identify traits.
  • Self-heals on refresh. GetValidToken back-fills identity from the refresh response for sessions created before this change, and preserves stored identity when a refresh response omits the user.

Test

  • Login
go run ./cmd/algolia auth login
  • Check token contains the correct data (token data + user id, email and name)
security find-generic-password -s algolia-cli -a oauth-token -w \
  | sed 's/^go-keyring-base64://' | base64 -d | jq .   # → includes user_id, email, name
  • Check on Segment that you see the Identity call with your user id attached
  • On subsequent commands, your userID should be attached to each command invocation

Preview

Screenshot 2026-06-02 at 11 21 05 Screenshot 2026-06-02 at 11 21 13

GROUT-350

@codacy-production
Copy link
Copy Markdown

codacy-production Bot commented Jun 2, 2026

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 30 complexity · 14 duplication

Metric Results
Complexity 30
Duplication 14

View in Codacy

TIP This summary will be updated as you push new changes.

@LorrisSaintGenez LorrisSaintGenez changed the title feat(identify): send user data to identify after login feat(identify): send user data to identify after oauth flow Jun 2, 2026
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