AuthClient
Defined in: auth-client.ts:162
Manages authentication and identity for Internet Computer web apps.
Example
Section titled “Example”const authClient = new AuthClient();
if (authClient.isAuthenticated()) { const identity = await authClient.getIdentity();}
await authClient.login({ onSuccess: () => console.log('Logged in!'),});Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new AuthClient(
options?):AuthClient
Defined in: auth-client.ts:171
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:169
Methods
Section titled “Methods”getIdentity()
Section titled “getIdentity()”getIdentity():
Promise<Identity>
Defined in: auth-client.ts:202
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:210
Checks whether the user has an active, non-expired session.
Returns
Section titled “Returns”boolean
login()
Section titled “login()”login(
options?):Promise<void>
Defined in: auth-client.ts:234
Opens the identity provider and requests a delegation.
Parameters
Section titled “Parameters”options?
Section titled “options?”Login options.
Returns
Section titled “Returns”Promise<void>
Throws
Section titled “Throws”When authentication fails and no onError callback is provided.
Example
Section titled “Example”await authClient.login({ onSuccess: () => console.log('Logged in!'), onError: (err) => console.error(err),});logout()
Section titled “logout()”logout(
options?):Promise<void>
Defined in: auth-client.ts:287
Clears the stored session and resets the client to an anonymous state.
Parameters
Section titled “Parameters”options?
Section titled “options?”Logout options.
returnTo?
Section titled “returnTo?”string
URL to navigate to after logout.
Returns
Section titled “Returns”Promise<void>