@idhub/identity-adapter-angular
Classes
IdentityHttpInterceptor
Defined in: identity-adapter-angular/src/http-interceptor.ts:24
Attaches the current identity id to every outgoing HttpClient request so a
backend can correlate its own logs with the vendor-side identity.
The header carries the userId once identified and the anonymous id before that — one header, one meaning ("who is this request from"), matching how identity-core models the state machine.
Registered only when IdentityModule.forRoot({ enableHttpInterceptor: true })
is used; an existing header on the request is never overwritten.
Implements
HttpInterceptor
Constructors
Constructor
new IdentityHttpInterceptor(
identity):IdentityHttpInterceptor
Defined in: identity-adapter-angular/src/http-interceptor.ts:25
Parameters
identity
Returns
Methods
intercept()
intercept(
request,next):Observable<HttpEvent<unknown>>
Defined in: identity-adapter-angular/src/http-interceptor.ts:27
Identifies and handles a given HTTP request.
Parameters
request
HttpRequest<unknown>
next
HttpHandler
The next interceptor in the chain, or the backend if no interceptors remain in the chain.
Returns
Observable<HttpEvent<unknown>>
An observable of the event stream.
Implementation of
HttpInterceptor.intercept
IdentityModule
Defined in: identity-adapter-angular/src/identity.module.ts:39
Providers-only Angular module. forRoot() is the single supported entry
point; importing IdentityModule bare intentionally registers nothing so a
lazily-loaded feature module can't accidentally create a second
IdentityClient (which would mean two competing anonymous ids).
Constructors
Constructor
new IdentityModule():
IdentityModule
Returns
Methods
forRoot()
staticforRoot(config):ModuleWithProviders<IdentityModule>
Defined in: identity-adapter-angular/src/identity.module.ts:40
Parameters
config
Returns
ModuleWithProviders<IdentityModule>
IdentityService
Defined in: identity-adapter-angular/src/identity.service.ts:27
Angular-facing wrapper around identity-core's IdentityClient.
The client is created in the constructor, which is what makes the
APP_INITIALIZER guarantee work: identity-core resolves the canonical
anonymous id and fans onAnonymous out to every provider synchronously
during createIdentityClient(), so by the time this constructor returns the
id exists and every provider has been notified.
State is republished as an RxJS BehaviorSubject so templates can use
state$ | async and get the current value immediately rather than waiting
for the next transition.
Implements
OnDestroy
Constructors
Constructor
new IdentityService(
config):IdentityService
Defined in: identity-adapter-angular/src/identity.service.ts:39
@Inject is explicit rather than metadata-driven: this package is built
with esbuild, which cannot emit design:paramtypes.
Parameters
config
Returns
Properties
state$
readonlystate$:Observable<IdentityState>
Defined in: identity-adapter-angular/src/identity.service.ts:33
Current identity state, replayed to every new subscriber.
Accessors
snapshot
Get Signature
get snapshot():
IdentityState
Defined in: identity-adapter-angular/src/identity.service.ts:59
Synchronous snapshot, for callers that cannot await an Observable —
notably IdentityHttpInterceptor, which must decide on a header value
inside intercept().
Returns
Methods
identify()
identify(
userId,traits?):void
Defined in: identity-adapter-angular/src/identity.service.ts:64
Fans out to every provider's onIdentify. Call once, at login.
Parameters
userId
string
traits?
Returns
void
ngOnDestroy()
ngOnDestroy():
void
Defined in: identity-adapter-angular/src/identity.service.ts:83
A callback method that performs custom clean-up, invoked immediately before a directive, pipe, or service instance is destroyed.
Returns
void
Implementation of
OnDestroy.ngOnDestroy
page()
page(
name?,properties?):void
Defined in: identity-adapter-angular/src/identity.service.ts:79
Fans out to every provider that implements onPage.
Parameters
name?
string
properties?
Returns
void
reset()
reset():
void
Defined in: identity-adapter-angular/src/identity.service.ts:69
Logout: issues a brand-new anonymous id and fans out onReset.
Returns
void
track()
track(
event,properties?):void
Defined in: identity-adapter-angular/src/identity.service.ts:74
Fans out to every provider that implements onTrack.
Parameters
event
string
properties?
Returns
void
Interfaces
AnonymousIdCookieConfig
Defined in: identity-core/build/esm/index.d.ts:52
Properties
domain?
optionaldomain?:string
Defined in: identity-core/build/esm/index.d.ts:56
Cookie domain, e.g. '.example.com' for cross-subdomain sharing.
httpOnly?
optionalhttpOnly?:boolean
Defined in: identity-core/build/esm/index.d.ts:60
Must stay readable by vendor client SDKs. Default: false.
maxAge?
optionalmaxAge?:number
Defined in: identity-core/build/esm/index.d.ts:58
Seconds. Default: 31536000 (1 year).
name?
optionalname?:string
Defined in: identity-core/build/esm/index.d.ts:54
Cookie name. Default: '_anon_id'.
sameSite?
optionalsameSite?:"Strict"|"Lax"|"None"
Defined in: identity-core/build/esm/index.d.ts:62
Default: 'Lax'.
secure?
optionalsecure?:boolean
Defined in: identity-core/build/esm/index.d.ts:64
Default: true in production, false in local dev over http.
IdentityModuleConfig
Defined in: identity-adapter-angular/src/config.ts:14
Everything IdentityModule.forRoot() accepts. Deliberately a superset of
identity-core's IdentityClientConfig — the adapter adds only Angular-level
concerns (enableHttpInterceptor) and re-exposes the rest verbatim so there
is exactly one shape to learn.
Properties
cookie?
optionalcookie?:AnonymousIdCookieConfig
Defined in: identity-adapter-angular/src/config.ts:18
Cookie settings for the canonical anonymous id.
enableHttpInterceptor?
optionalenableHttpInterceptor?:boolean
Defined in: identity-adapter-angular/src/config.ts:24
Registers IdentityHttpInterceptor in HTTP_INTERCEPTORS so every
HttpClient request carries the current identity id. Off by default —
sending an id to a third-party API is a decision the app must opt into.
onWarning?
optionalonWarning?: (code,message) =>void
Defined in: identity-adapter-angular/src/config.ts:26
Forwarded to identity-core's IdentityClientConfig.onWarning.
Parameters
code
message
string
Returns
void
providers
providers:
IdentityProvider[]
Defined in: identity-adapter-angular/src/config.ts:16
Vendor packages implementing identity-core's IdentityProvider.
IdentityProvider
Defined in: identity-core/build/esm/index.d.ts:69
Every vendor package (identity-provider-segment, -launchdarkly, -fullstory, or a future 4th vendor) implements exactly this interface. identity-core never imports a concrete provider — only this shape.
Properties
name
readonlyname:string
Defined in: identity-core/build/esm/index.d.ts:71
Unique name for logging/debugging, e.g. 'segment'.
Methods
onAnonymous()
onAnonymous(
anonymousId):void|Promise<void>
Defined in: identity-core/build/esm/index.d.ts:75
Called once, as early as possible, before the user is known. Segment/LaunchDarkly use this; FullStory's implementation is a documented no-op (see provider table).
Parameters
anonymousId
Returns
void | Promise<void>
onIdentify()
onIdentify(
userId,anonymousId,traits?):void|Promise<void>
Defined in: identity-core/build/esm/index.d.ts:80
Called exactly once per login/registration. Implementations must be idempotent if called twice with the SAME userId (e.g. traits update), but IdentityClient guards against calls with a DIFFERENT userId while already identified (see IdentityClientConfig.onWarning).
Parameters
userId
string
anonymousId
traits?
Returns
void | Promise<void>
onPage()?
optionalonPage(name?,properties?):void|Promise<void>
Defined in: identity-core/build/esm/index.d.ts:89
Optional: page-view tracking, same rationale as onTrack.
Parameters
name?
string
properties?
Returns
void | Promise<void>
onReset()
onReset(
newAnonymousId):void|Promise<void>
Defined in: identity-core/build/esm/index.d.ts:83
Called on logout. Receives the newly generated anonymous id (the old one is intentionally not passed — providers must not persist it).
Parameters
newAnonymousId
Returns
void | Promise<void>
onTrack()?
optionalonTrack(event,properties?):void|Promise<void>
Defined in: identity-core/build/esm/index.d.ts:87
Optional: only implement if the vendor has an event-tracking API distinct from identify (Segment/FullStory track events; a future flag-only provider might omit this entirely).
Parameters
event
string
properties?
Returns
void | Promise<void>
Type Aliases
AnonymousId
AnonymousId =
string&object
Defined in: identity-core/build/esm/index.d.ts:6
Canonical anonymous id. Branded so it can't be silently mixed up with a plain userId string at call sites.
Type Declaration
__brand
readonly__brand:"AnonymousId"
IdentityEvent
IdentityEvent = {
anonymousId:AnonymousId;type:"anonymous_id_created"; } | {anonymousId:AnonymousId;traits?:Traits;type:"identified";userId:UserId; } | {anonymousId:AnonymousId;previousAnonymousId:AnonymousId;type:"reset"; } | {event:string;properties?:Traits;type:"track"; } | {name?:string;properties?:Traits;type:"page"; } | {code:IdentityWarningCode;message:string;type:"warning"; }
Defined in: identity-core/build/esm/index.d.ts:22
Emitted on every state transition; adapters subscribe to drive React context / Angular Observable updates.
Union Members
Type Literal
{ anonymousId: AnonymousId; type: "anonymous_id_created"; }
Type Literal
{ anonymousId: AnonymousId; traits?: Traits; type: "identified"; userId: UserId; }
Type Literal
{ anonymousId: AnonymousId; previousAnonymousId: AnonymousId; type: "reset"; }
Type Literal
{ event: string; properties?: Traits; type: "track"; }
Type Literal
{ name?: string; properties?: Traits; type: "page"; }
Type Literal
{ code: IdentityWarningCode; message: string; type: "warning"; }
Dev-mode-only warning event, e.g. re-identify with a different userId while already identified (see Risks: FullStory split-not-merge). Never fired in production builds.
IdentityState
IdentityState = {
anonymousId:AnonymousId;status:"anonymous"; } | {anonymousId:AnonymousId;status:"identified";traits?:Traits;userId:UserId; }
Defined in: identity-core/build/esm/index.d.ts:11
IdentityWarningCode
IdentityWarningCode =
"reidentify_with_different_user_id"|"provider_init_failed"|"track_before_ready"
Defined in: identity-core/build/esm/index.d.ts:51
Traits
Traits =
Record<string,string|number|boolean|null|undefined>
Defined in: identity-core/build/esm/index.d.ts:3
Free-form traits attached to a user or event. Vendor packages map this onto their own SDK's trait/property shape internally.
UserId
UserId =
string
Defined in: identity-core/build/esm/index.d.ts:10
Vendor-supplied known user id (e.g. memberId, sub claim).
Variables
IDENTITY_CONFIG
constIDENTITY_CONFIG:InjectionToken<IdentityModuleConfig>
Defined in: identity-adapter-angular/src/config.ts:34
DI token holding the resolved forRoot config. Exported so tests and
advanced consumers can re-provide it; app code should use
IdentityModule.forRoot().
IDENTITY_ID_HEADER
constIDENTITY_ID_HEADER:"X-Identity-Id"="X-Identity-Id"
Defined in: identity-adapter-angular/src/config.ts:39
Request header used by IdentityHttpInterceptor.
Functions
identityInitializerFactory()
identityInitializerFactory(
service): () =>Promise<void>
Defined in: identity-adapter-angular/src/identity.module.ts:28
APP_INITIALIZER factory.
Angular blocks bootstrap — and therefore the first route render — until every
APP_INITIALIZER promise settles. Because IdentityService is listed in
deps, Angular must construct it before calling this factory, and
constructing it runs identity-core's createIdentityClient(), which resolves
the canonical anonymous id and fans onAnonymous out to every registered
provider synchronously.
Awaiting state$ (a BehaviorSubject, so it already holds the seeded
anonymous state) makes that ordering explicit and gives the initializer a
real Promise to hand back rather than a bare undefined.
Known limitation: identity-core's createIdentityClient does not surface the
promises returned by async onAnonymous implementations, so this initializer
guarantees every provider has been called — not that a provider's own
network round-trip has finished. Providers that need to gate rendering on
their own readiness should contribute a second APP_INITIALIZER.
Parameters
service
Returns
() => Promise<void>