@idhub/identity-adapter-angular/server
Interfaces
IdentityExpressMiddlewareConfig
Defined in: identity-adapter-angular/src/server/express-middleware.ts:31
Properties
cookie?
optionalcookie?:AnonymousIdCookieConfig
Defined in: identity-adapter-angular/src/server/express-middleware.ts:32
IdentityRequestLike
Defined in: identity-adapter-angular/src/server/express-middleware.ts:20
Minimal structural shapes for the bits of Express's req/res this
middleware touches.
Why structural types instead of @types/express: this package must not add a
dependency (even a dev one) that leaks Express into consumers' type graphs,
and the middleware only ever reads one request header and appends one
response header. Express's real Request/Response satisfy these shapes
structurally, so app.use(identityExpressMiddleware()) type-checks with no
cast in an Express app.
Properties
anonymousId?
optionalanonymousId?:AnonymousId
Defined in: identity-adapter-angular/src/server/express-middleware.ts:23
Set by this middleware so downstream handlers / SSR can read the id.
headers
headers:
object
Defined in: identity-adapter-angular/src/server/express-middleware.ts:21
cookie?
optionalcookie?:string
IdentityResponseLike
Defined in: identity-adapter-angular/src/server/express-middleware.ts:26
Methods
getHeader()
getHeader(
name):string|number|string[] |undefined
Defined in: identity-adapter-angular/src/server/express-middleware.ts:27
Parameters
name
string
Returns
string | number | string[] | undefined
setHeader()
setHeader(
name,value):unknown
Defined in: identity-adapter-angular/src/server/express-middleware.ts:28
Parameters
name
string
value
string | number | readonly string[]
Returns
unknown
Functions
identityExpressMiddleware()
identityExpressMiddleware(
config?): (req,res,next) =>void
Defined in: identity-adapter-angular/src/server/express-middleware.ts:57
Companion middleware for Angular Universal / SSR.
Angular has no request-time middleware of its own, so the APP_INITIALIZER
guarantee only covers the browser bootstrap. Mounting this in the Express
server that hosts the Universal build gives the same guarantee server-side:
the canonical anonymous id exists on the very first request, before any
component renders, so the server render and the subsequent client bootstrap
agree on one id instead of the client minting a second one.
Implementation note: it uses identity-core's lower-level cookie primitives
(parseCookieHeader / serializeAnonymousIdCookie) rather than
getOrCreateAnonymousIdFromRequest, because the latter takes a Web Standard
Request and Express exposes a Node IncomingMessage. Wrapping every
request in a synthetic Request just to read one header would allocate on
every hit and still need unwrapping to append the Set-Cookie; the cookie
semantics (name/defaults/serialization) still come from identity-core, so
there is no duplicated cookie logic — only a different transport.
Set-Cookie is appended, never replaced, so it composes with session or
auth cookies set by other middleware.
Parameters
config?
IdentityExpressMiddlewareConfig = {}
Returns
(req, res, next) => void