Skip to content

AuthClient

Defined in: auth-client.ts:150

Manages authentication and identity for Internet Computer web apps.

const authClient = new AuthClient();
const identity = authClient.isAuthenticated()
? await authClient.getIdentity()
: await authClient.signIn();

new AuthClient(options?): AuthClient

Defined in: auth-client.ts:159

AuthClientCreateOptions = {}

AuthClient

idleManager: IdleManager | undefined

Defined in: auth-client.ts:157

getIdentity(): Promise<Identity>

Defined in: auth-client.ts:190

Returns the current identity, restoring a previous session if available.

Promise<Identity>


isAuthenticated(): boolean

Defined in: auth-client.ts:198

Checks whether the user has an active, non-expired session.

boolean


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.

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.

Promise<SignedAttributes>

Signed attribute data and signature.

When the identity provider returns an error or an invalid response.


signIn(options?): Promise<Identity>

Defined in: auth-client.ts:222

Opens the identity provider, requests a delegation, and returns the authenticated identity.

AuthClientSignInOptions

Sign-in options.

Promise<Identity>

The authenticated identity.

When authentication fails.

try {
const identity = await authClient.signIn();
} catch (error) {
console.error('Sign-in failed:', error);
}

signOut(options?): Promise<void>

Defined in: auth-client.ts:314

Clears the stored session and resets the client to an anonymous state.

Sign-out options.

string

URL to navigate to after sign-out.

Promise<void>