Skip to content

Design pillar: identity state machine (HMAC/JWT first-class, no session leaks) #4

@productdevbook

Description

@productdevbook

Identity is the second-most-reported failure class across competitors — stale users, HMAC rejections, session leaks across logins, custom attributes dropped silently.

Evidence

Unified identity model

```ts
identify({
id: string
email?: string
name?: string
phone?: string
// Typed verification — per-provider discriminated union
verification?:
| { kind: "hmac"; hash: string } // Intercom, Chatwoot, Beacon, Gist
| { kind: "jwt"; token: string } // Drift, Freshchat
| { kind: "callback"; getToken: () => Promise } // Zendesk Messenger
}): Promise
```

Rules

  1. State machine: `anonymous → identified(u1) → identified(u2) → anonymous`. Every transition (a) calls provider-specific reset (b) verifies window object cleared (c) emits `onIdentityChange`.
  2. `identify()` returns a `Promise` that resolves only when the next ping confirms the new identity.
  3. Provider config flag `enforceVerification: true` makes `verification` required at the type level. Missing ⇒ compile error.
  4. Never compute HMACs in the browser. Document that `hash` must come from your server.
  5. For callback-based flows (Zendesk), invoke `getToken` on 401 refresh.
  6. Expose `onIdentityChange((prev, next) => …)` so consumers can mirror into their analytics.

Metadata

Metadata

Assignees

No one assigned

    Labels

    competitor-analysisDerived from OSS competitor issue patternsdesign-pillarCore design decisionsidentityidentify / HMAC / JWT / session

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions