Deleting passkeys from your backend and the user's local device
Deleting a passkey from your vault
Section titled “Deleting a passkey from your vault”Use the @passlock/server library to remove a passkey from your vault:
import { deletePasskey, isNotFoundError } from "@passlock/server";
// get these from your development tenancy settingsconst tenancyId = "myTenancyId";const apiKey = "myApiKey";
try { const result = await deletePasskey({ passkeyId, tenancyId, apiKey });} catch (e) { if (isNotFoundError(e)) { // passkey not found in the vault }}import { deletePasskey, isNotFoundError} from "@passlock/server/safe";
// get these from your development tenancy settingsconst tenancyId = "myTenancyId";const apiKey = "myApiKey";
const result = await deletePasskey({ passkeyId, tenancyId, apiKey });
if (result.success) { // success} else if (isNotFoundError(result.error)) { // passkey not found in the vault} else { console.error(result.error.message);}Deleting a passkey from a device
Section titled “Deleting a passkey from a device”Use the @passlock/client library to remove a passkey from a user’s device:
import { deletePasskey, isDeleteError } from "@passlock/client";
// get this from your development tenancy settingsconst tenancyId = "myTenancyId";const passkeyId = "myPasskeyId";
try { const result = await deletePasskey({ tenancyId, passkeyId });} catch (e) { if (isDeleteError(e)) { console.log(e.message); }}import { deletePasskey } from "@passlock/client/safe";
// get this from your development tenancy settingsconst tenancyId = "myTenancyId";const passkeyId = "myPasskeyId";
const result = await deletePasskey({ tenancyId, passkeyId });
if (result.success) { // happy days} else { console.log(result.error.message);}Backend and frontend deletion
Section titled “Backend and frontend deletion”You can first delete a passkey from your vault, then pass the result to your frontend code…
import { deletePasskey } from "@passlock/server";
const result = await deletePasskey({ passkeyId, tenancyId, apiKey });
// send the DeletedPasskey payload to your frontendres.send(JSON.stringify(result)); import { deletePasskey } from "@passlock/server/safe";
const result = await deletePasskey({ passkeyId, tenancyId, apiKey });
if (result.success) { // send the DeletedPasskey payload to your frontend res.send(JSON.stringify(result.value)); }import { deletePasskey } from "@passlock/client";
// result of calling deletePasskey in your backendconst backendDeletionResult = { _tag: "DeletedPasskey", deleted: { credentialId: "...", userId: "...", rpId: "..." },};
try { const result = await deletePasskey(backendDeletionResult.deleted);} catch (e) { ... }import { deletePasskey } from "@passlock/client/safe";
// result of calling deletePasskey in your backendconst backendDeletionResult = { _tag: "DeletedPasskey", deleted: { credentialId: "...", userId: "...", rpId: "..." },};
const result = await deletePasskey(backendDeletionResult.deleted);
if (!result.success) { console.error(result.error.message);}Deletion following an OrphanedPasskeyError
Section titled “Deletion following an OrphanedPasskeyError”During client side authentication, if you receive an OrphanedPasskeyError, pass that error into the deletePasskey function:
import { authenticatePasskey, deletePasskey, isOrphanedPasskeyError,} from "@passlock/client";
try { const result = await authenticatePasskey({ ... });} catch (e) { if (isOrphanedPasskeyError(e)) { if (confirm("Passkey invalid, remove it?")) { await deletePasskey(e); } }}import { authenticatePasskey, deletePasskey, isOrphanedPasskeyError,} from "@passlock/client/safe";
const result = await authenticatePasskey({ ... });
if (!result.success && isOrphanedPasskeyError(result.error)) { if (confirm("Passkey invalid, remove it?")) { const deletion = await deletePasskey(result.error);
if (!deletion.success) { console.error(deletion.error.message); } }} else if (!result.success) { console.error(result.error.message);}