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:268
Requests signed identity attributes from the identity provider.
Parameters
Section titled “Parameters”params
Section titled “params”Request parameters.
string[]
Attribute keys to request (e.g. ['email', 'name']).
Uint8Array
32-byte nonce issued by the RP canister.
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:306
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>