Skip to main content

PasskeyManager

@loginid/websdk3Docs


@loginid/websdk3 / Internal Modules / PasskeyManager

Class: PasskeyManager

Extends LoginIDBase to manage Passkeys, including listing, renaming, and deleting passkeys.

Extends

Extended by

Constructors

new PasskeyManager()

new PasskeyManager(config): PasskeyManager

Initializes a new instance of PasskeyManager with the provided configuration.

Parameters

config: LoginIDConfig

Configuration object for LoginID.

Returns

PasskeyManager

Overrides

LoginIDBase.constructor

Properties

session

readonly session: SessionManager

Instance of SessionManager, providing access to the session management methods.

Inherited from

LoginIDBase.session

Methods

deletePasskey()

deletePasskey(id, options): Promise<void>

Delete a specified passkey by ID from LoginID. The user must be fully authorized for this call to succeed.

Parameters

id: string

The ID of the passkey to delete.

options: DeletePasskeyOptions = {}

Additional options for deleting the passkey.

Returns

Promise<void>

A promise that resolves when the operation completes successfully.

Example

import { LoginIDWebSDK } from "@loginid/websdk3";

// Obtain credentials from LoginID
const BASE_URL = process.env.BASE_URL;

// Initialize the SDK with your configuration
const config = {
baseUrl: BASE_URL,
};

// Use the SDK components for signup and signin
const lid = new LoginIDWebSDK(config);

const passkeyId = "abc123";

// Delete the passkey user credential
try {
// Signin with passkey
const signinResult = await lid.authenticateWithPasskey(username);

// Find a way to retrieve passkey ID
await lid.deletePasskey(passkeyId);
// Passkey credential successfully deleted
} catch (error) {
// Handle errors
console.error("Error deleting passkey:", error);
}

listPasskeys()

listPasskeys(options): Promise<PasskeyCollection>

This method returns list of passkeys associated with the current user. The user must be fully authorized for this call to succeed.

Parameters

options: ListPasskeysOptions = {}

Additional options for listing passkeys.

Returns

Promise<PasskeyCollection>

A collection of passkeys.

Example

import { LoginIDWebSDK } from "@loginid/websdk3";

// Obtain credentials from LoginID
const BASE_URL = process.env.BASE_URL;

// Initialize the SDK with your configuration
const config = {
baseUrl: BASE_URL,
};

// Use the SDK components for signup and signin
const lid = new LoginIDWebSDK(config);

// Button click handler for signing in
async function handleSigninButtonClick() {
const username = "billy@loginid.io";

try {
// Sign in with a passkey
await lid.authenticateWithPasskey(username);

// List all user credentials
const passkeys = await lid.listPasskeys();
// Handle the sign-in result
} catch (error) {
// Handle errors
console.error("Error during obtaining passkeys:", error);
}
}

// Attach the click handler to a button
const signinButton = document.getElementById("signinButton");
signinButton.addEventListener("click", handleSigninButtonClick);

renamePasskey()

renamePasskey(id, name, options): Promise<void>

Renames a specified passkey by ID. The user must be fully authorized for this call to succeed.

Parameters

id: string

The ID of the passkey to rename.

name: string

The new name for the passkey.

options: RenamePasskeyOptions = {}

Additional options for renaming the passkey.

Returns

Promise<void>

A promise that resolves when the operation completes successfully.

Example

import { LoginIDWebSDK } from "@loginid/websdk3";

// Obtain credentials from LoginID
const BASE_URL = process.env.BASE_URL;

// Initialize the SDK with your configuration
const config = {
baseUrl: BASE_URL,
};

// Use the SDK components for signup and signin
const lid = new LoginIDWebSDK(config);

const passkeyId = "abc123";
const newCredName = "New Passkey Credential Name";

// Rename the passkey user credential
try {
// Signin with passkey
await lid.authenticateWithPasskey(username);

// Find a way to retrieve passkey ID
await lid.renamePasskey(passkeyId, newCredName);
// Passkey credential successfully renamed
} catch (error) {
// Handle errors
console.error("Error during passkey credential renaming:", error);
}