AuthClient
Defined in: auth-client.ts:150
Manages authentication and identity for Internet Computer web apps.
Example
Section titled “Example”const authClient = new AuthClient();
const identity = authClient.isAuthenticated() ? await authClient.getIdentity() : await authClient.signIn();Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new AuthClient(
options?):AuthClient
Defined in: auth-client.ts:159
Parameters
Section titled “Parameters”options?
Section titled “options?”Returns
Section titled “Returns”AuthClient
Properties
Section titled “Properties”idleManager
Section titled “idleManager”idleManager:
IdleManager|undefined
Defined in: auth-client.ts:157
Methods
Section titled “Methods”getIdentity()
Section titled “getIdentity()”getIdentity():
Promise<Identity>
Defined in: auth-client.ts:190
Returns the current identity, restoring a previous session if available.
Returns
Section titled “Returns”Promise<Identity>
isAuthenticated()
Section titled “isAuthenticated()”isAuthenticated():
boolean
Defined in: auth-client.ts:198
Checks whether the user has an active, non-expired session.
Returns
Section titled “Returns”boolean
requestAttributes()
Section titled “requestAttributes()”requestAttributes(
params):Promise<SignedAttributes>
Defined in: auth-client.ts:276
Requests signed identity attributes from the identity provider.
The nonce may be a Uint8Array or a Promise<Uint8Array>. Passing a
promise lets the identity provider window open while the nonce (typically
fetched from the RP canister) is still being resolved, avoiding a perceived
delay before the user sees the prompt. Auto-close of the signer transport
channel is temporarily disabled while awaiting the promise so the window
cannot be closed out from under the pending flow.
Parameters
Section titled “Parameters”params
Section titled “params”Request parameters.
string[]
Attribute keys to request (e.g. ['email', 'name']).
Uint8Array<ArrayBufferLike> | Promise<Uint8Array<ArrayBufferLike>>
32-byte nonce issued by the RP canister, or a promise resolving to one.
Returns
Section titled “Returns”Promise<SignedAttributes>
Signed attribute data and signature.
Throws
Section titled “Throws”When the identity provider returns an error or an invalid response.
signIn()
Section titled “signIn()”signIn(
options?):Promise<Identity>
Defined in: auth-client.ts:222
Opens the identity provider, requests a delegation, and returns the authenticated identity.
Parameters
Section titled “Parameters”options?
Section titled “options?”Sign-in options.
Returns
Section titled “Returns”Promise<Identity>
The authenticated identity.
Throws
Section titled “Throws”When authentication fails.
Example
Section titled “Example”try { const identity = await authClient.signIn();} catch (error) { console.error('Sign-in failed:', error);}signOut()
Section titled “signOut()”signOut(
options?):Promise<void>
Defined in: auth-client.ts:314
Clears the stored session and resets the client to an anonymous state.
Parameters
Section titled “Parameters”options?
Section titled “options?”Sign-out options.
returnTo?
Section titled “returnTo?”string
URL to navigate to after sign-out.
Returns
Section titled “Returns”Promise<void>