Add setUser helper to core (fixes broken user identification in node + electron)#64
Merged
Conversation
…ity via report pipeline
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
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
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/nodeand@flareapp/electronwere emittingenduser.*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, theUser.tsxcontext renderer, and the protocol doc). Nothing readsenduser.*.What changed
@flareapp/core: newFlare.setUser(user: User | null): this. Mapsid→user.id(stringified),email→user.email,fullName→user.full_name,ipAddress→client.address; extra keys bundle intouser.attributes;setUser(null)clears. Sugar over the active scope'spendingAttributes, so it is scope-aware for free (browser/electron single scope, node per-request). ExposesUSER_IDENTITY_KEYS+userIdentityAttributes(scope)as the single source of truth.@flareapp/node: removed the divergentsetUseroverride,NodeScope.user, the providersetUser, theenduser.*collector block, and the localUsertype. Inherits coresetUser;Userre-exported from core.@flareapp/electron: removed thesetUseroverride,private userfield,projectUser, and theElectronUsertype. Keeps amainScopereference 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-exportsUser.setUserdocumented across the js/node/electron/react/vue/svelte/sveltekit READMEs.Breaking changes (pre-1.0 packages, intentional)
@flareapp/node:setUser'susernamefield removed (usefullName, or pass as an extra key →user.attributes).@flareapp/electron:ElectronUsertype removed (Userfrom core);usernamelikewise gone.enduser.*→user.*. This is the fix.Follow-ups (out of scope)
docs/handoffs/2026-06-23-flare-docs-identifying-users.md.setUserthrough the real fetch path (unit tests already assert the sent report payload).Test Plan
npm run typescriptclean repo-widenpm run buildclean (all packages)npm run testgreen across all workspacesuser.*/client.address/user.attributeson the sent report payload, null-clear, overwrite-drops-omitted, and theid: nullguarduser.*on the report and per-request scope isolationuser.*and that main identity overrides a renderer-supplieduser.idon forwarded reportsenduser.*remains in shippingsrc