Skip to content

AuthLike

Defined in: core/src/client.ts:98

A sign-in the client can own: what @icp-sdk/auth 11’s AuthClient and the auth of createTestClient() from @ic-reactor/core/testing both are, with no adapter.

The client reads getStatus() and getPrincipal() synchronously to decide who calls, asks getIdentity() for the identity to sign with only when it builds or checks an agent for a signed-in principal, and re-reads both after every subscribe() notification. signIn() and signOut() are forwarded from Client.signIn and Client.signOut, and dispose(), when present, is called from Client.dispose: the client owns the auth its factory built.

Another sign-in source that hands over an Identity (a delegation, such as a hand-rolled session gives, or a local key) fits by implementing these six methods, and dispose() if it holds anything. A wallet that signs each call itself (ICRC-25 and ICRC-49: OISY, Plug, NFID accounts) gives no Identity and does not fit: the Auth guide shows writes through such a wallet beside the client. A source’s getIdentity() should return the same object until the identity really changes: the client builds a new agent for every new identity object it is handed, and reads a new object for the same principal as a renewal.

getPrincipal(): { toText: string; } | undefined

Defined in: core/src/client.ts:100

Who calls are accepted as, or undefined when nobody can act.

{ toText: string; } | undefined


getStatus(): object

Defined in: core/src/client.ts:109

Who is signed in. Only "signed-in" makes the client call as AuthLike.getPrincipal; every other state calls anonymously. The four named states are @icp-sdk/auth 11’s; any other string, such as a state a later @icp-sdk/auth adds, is accepted and reads as "anonymous" in AuthState, so an upgrade of the auth library does not stop an app compiling.

readonly state: string & object | "signed-in" | "signed-in-elsewhere" | "expired" | "signed-out"

readonly optional expiresAtMs?: number

When the session ends, in milliseconds since the epoch (Date.now()’s scale), as AuthClient 11 reports it. While the status is "signed-in" or "signed-in-elsewhere", the client sets a timer for it and tells its listeners when the session ends: an auth whose status turns "expired" by the clock, as AuthClient’s does, need not notify for it. It is AuthState.expiresAt while signed in.


getIdentity(): Promise<Identity>

Defined in: core/src/client.ts:127

The identity to sign calls with while signed in.

Promise<Identity>


subscribe(listener): () => void

Defined in: core/src/client.ts:129

Calls listener after each change of who is signed in. Returns a function that stops listening.

() => void

() => void


signIn(options?): Promise<unknown>

Defined in: core/src/client.ts:130

unknown

Promise<unknown>


signOut(options?): Promise<unknown>

Defined in: core/src/client.ts:131

unknown

Promise<unknown>


optional dispose(): void

Defined in: core/src/client.ts:133

Releases what the auth holds. Called once, from Client.dispose.

void