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.
Methods
Section titled “Methods”getPrincipal()
Section titled “getPrincipal()”getPrincipal(): {
toText:string; } |undefined
Defined in: core/src/client.ts:100
Who calls are accepted as, or undefined when nobody can act.
Returns
Section titled “Returns”{ toText: string; } | undefined
getStatus()
Section titled “getStatus()”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.
Returns
Section titled “Returns”
readonlystate:string&object|"signed-in"|"signed-in-elsewhere"|"expired"|"signed-out"
expiresAtMs?
Section titled “expiresAtMs?”
readonlyoptionalexpiresAtMs?: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()
Section titled “getIdentity()”getIdentity():
Promise<Identity>
Defined in: core/src/client.ts:127
The identity to sign calls with while signed in.
Returns
Section titled “Returns”Promise<Identity>
subscribe()
Section titled “subscribe()”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.
Parameters
Section titled “Parameters”listener
Section titled “listener”() => void
Returns
Section titled “Returns”() => void
signIn()
Section titled “signIn()”signIn(
options?):Promise<unknown>
Defined in: core/src/client.ts:130
Parameters
Section titled “Parameters”options?
Section titled “options?”unknown
Returns
Section titled “Returns”Promise<unknown>
signOut()
Section titled “signOut()”signOut(
options?):Promise<unknown>
Defined in: core/src/client.ts:131
Parameters
Section titled “Parameters”options?
Section titled “options?”unknown
Returns
Section titled “Returns”Promise<unknown>
dispose()?
Section titled “dispose()?”
optionaldispose():void
Defined in: core/src/client.ts:133
Releases what the auth holds. Called once, from Client.dispose.
Returns
Section titled “Returns”void