Skip to content

Deleting passkeys from your backend and the user's local device

Use the @passlock/server library to remove a passkey from your vault:

import { deletePasskey, isNotFoundError } from "@passlock/server";
// get these from your development tenancy settings
const tenancyId = "myTenancyId";
const apiKey = "myApiKey";
try {
const result = await deletePasskey({ passkeyId, tenancyId, apiKey });
} catch (e) {
if (isNotFoundError(e)) {
// passkey not found in the vault
}
}

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 settings
const tenancyId = "myTenancyId";
const passkeyId = "myPasskeyId";
try {
const result = await deletePasskey({ tenancyId, passkeyId });
} catch (e) {
if (isDeleteError(e)) {
console.log(e.message);
}
}

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 frontend
res.send(JSON.stringify(result));
import { deletePasskey } from "@passlock/client";
// result of calling deletePasskey in your backend
const backendDeletionResult = {
_tag: "DeletedPasskey",
deleted: { credentialId: "...", userId: "...", rpId: "..." },
};
try {
const result = await deletePasskey(backendDeletionResult.deleted);
} catch (e) { ... }

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