Skip to content

Add setUser helper to core (fixes broken user identification in node + electron)#64

Merged
DriesH merged 16 commits into
mainfrom
set-user-context
Jun 23, 2026
Merged

Add setUser helper to core (fixes broken user identification in node + electron)#64
DriesH merged 16 commits into
mainfrom
set-user-context

Conversation

@DriesH

@DriesH DriesH commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds a unified setUser() helper to @flareapp/core, inherited by every SDK, that emits the flat attribute keys the Flare backend actually reads. This also fixes a shipped bug: @flareapp/node and @flareapp/electron were emitting enduser.* keys, which the backend never reads, so users set via those SDKs were silently never identified.

Backend reads only user.id, user.email, user.full_name, user.attributes, client.address (verified in the flareapp.io repo: RawReport.php, the User.tsx context renderer, and the protocol doc). Nothing reads enduser.*.

What changed

  • @flareapp/core: new Flare.setUser(user: User | null): this. Maps iduser.id (stringified), emailuser.email, fullNameuser.full_name, ipAddressclient.address; extra keys bundle into user.attributes; setUser(null) clears. Sugar over the active scope's pendingAttributes, so it is scope-aware for free (browser/electron single scope, node per-request). Exposes USER_IDENTITY_KEYS + userIdentityAttributes(scope) as the single source of truth.
  • @flareapp/node: removed the divergent setUser override, NodeScope.user, the provider setUser, the enduser.* collector block, and the local User type. Inherits core setUser; User re-exported from core.
  • @flareapp/electron: removed the setUser override, private user field, projectUser, and the ElectronUser type. Keeps a mainScope reference so the forwarded-renderer overlay can stamp main-authoritative identity (sourced from the same scope core writes to) onto reports that bypass core's pipeline.
  • @flareapp/js: re-exports User.
  • Docs: setUser documented across the js/node/electron/react/vue/svelte/sveltekit READMEs.

Breaking changes (pre-1.0 packages, intentional)

  • @flareapp/node: setUser's username field removed (use fullName, or pass as an extra key → user.attributes).
  • @flareapp/electron: ElectronUser type removed (User from core); username likewise gone.
  • Both: emitted keys change enduser.*user.*. This is the fix.

Follow-ups (out of scope)

  • Flare docs site (separate flareapp.io repo): a "Data collection > Identifying users" page for the JS SDKs. Handoff instructions prepared at docs/handoffs/2026-06-23-flare-docs-identifying-users.md.
  • Deferred Playwright e2e exercising setUser through the real fetch path (unit tests already assert the sent report payload).

Test Plan

  • npm run typescript clean repo-wide
  • npm run build clean (all packages)
  • npm run test green across all workspaces
  • Core unit tests assert user.*/client.address/user.attributes on the sent report payload, null-clear, overwrite-drops-omitted, and the id: null guard
  • Node integration test asserts user.* on the report and per-request scope isolation
  • Electron test asserts main-origin user.* and that main identity overrides a renderer-supplied user.id on forwarded reports
  • No enduser.* remains in shipping src

DriesH added 16 commits June 23, 2026 11:15
receiveRendererReport only added the identity keys main had set, so
renderer-supplied user.* keys survived: a renderer could identify users
main never set, and a partial main identity mixed with leftover renderer
keys. Clear all USER_IDENTITY_KEYS off the report before stamping main's,
matching the config-field handling. Adds regression tests for the
partial-main and main-unset cases.

Also from the review:
- core: derive USER_IDENTITY_KEYS from a USER_FIELD_KEYS map so setUser's
  set pass and clear pass share one source for the key literals
- core: document the User typo trap (misspelled known field falls into
  user.attributes)
- node: drop stale "authenticated user" line from the collector JSDoc
@DriesH DriesH merged commit 83347a0 into main Jun 23, 2026
3 checks passed
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