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


logout(options?): Promise<void>

Defined in: auth-client.ts:306

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

Logout options.

string

URL to navigate to after logout.

Promise<void>


requestAttributes(params): Promise<SignedAttributes>

Defined in: auth-client.ts:268

Requests signed identity attributes from the identity provider.

Request parameters.

string[]

Attribute keys to request (e.g. ['email', 'name']).

Uint8Array

32-byte nonce issued by the RP canister.

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);
}