Skip to content

Add user identity (setUserId / logout) - #13

Open
ahsanalidotme wants to merge 1 commit into
mainfrom
feat/user-identity
Open

ahsanalidotme wants to merge 1 commit into
mainfrom
feat/user-identity

Conversation

@ahsanalidotme

@ahsanalidotme ahsanalidotme commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Closes linktrail-io/linktrail-backend#112

Backend PR (deploy first, SDKs send userId which older backends reject with 400): https://github.com/linktrail-io/linktrail-backend/pull/139
The backend PR (POST /v1/events/identify + optional userId on events) must be deployed before this is released.

What

LinkTrail.setUserId(id): Promise<void>, LinkTrail.logout(): Promise<void>, LinkTrail.getUserId(): Promise<string | null>.

  • Validation ^[A-Za-z0-9_.:-]{1,128}$; invalid id rejects with code: 'invalid_user_id', nothing stored/sent.
  • Persisted across launches (wrapper-owned: UserDefaults / SharedPreferences, no new dependency).
  • Consent: the id is never forwarded while consent is denied/undecided; forwarded once on grant (or at configure when requireConsent: false); revoking clears it on the native side. logout() clears locally, no network call.
  • Logic lives in new src/identity.ts (pure TS, injected bridge). Tests: npm test (node:test + tsx; 11 tests: validation, persistence, consent gating, logout, failure swallowing).

Design decision and limits

The native SDKs perform all HTTP and own the device id (internal), so the JS layer cannot call /v1/events/identify or add userId to events itself. I did not depend on unreleased native APIs or bump pins. Instead the wrapper owns identity state and hands the id to the native SDK through a new forwardUserId bridge method:

  • Android: reflective lookup of setUserId(String) / logout() on the SDK, so it compiles against io.linktrail:sdk:0.0.5 and delivers automatically once the pin moves to a release that has them (method names assumed from the issue; must match the other agent's Android PR).
  • iOS: Swift cannot probe for a missing method, so forwardUserId returns false for now. Needs a one-line wrapper change when the pod pin moves to a release with identity.
  • With the currently pinned native SDKs nothing is transmitted: the id is validated, persisted and consent-gated only. Requires native SDK >= the first release with identity support (version TBD).

Checks

npm run typecheck, npm run lint (0 errors, warnings pre-existing/no-deep-imports), npm run prepare, codegen validation, npm test all pass locally.
CI does not run tests; adding npm test to .github/workflows/ci.yml is a follow-up (workflow files are not touched here).

Unverified

  • No device/simulator run; Kotlin/Swift/ObjC++ changes were not compiled (only codegen validated).
  • Reflection method names vs. the native SDK PRs; end-to-end delivery to the backend.
  • package-lock.json changed only for the new tsx devDependency.

🤖 Generated with Claude Code

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