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 { Passlock, isNotFoundError } from "@passlock/server";
// get these from your development tenancy settings
const tenancyId = "myTenancyId";
const apiKey = "myApiKey";
const passlock = new Passlock({ tenancyId, apiKey });
const result = await passlock.deletePasskey({ passkeyId });
if (result.success) {
// success
} else if (isNotFoundError(result.error)) {
// passkey not found in the vault
} else {
console.error(result.error.message);
}
Choose your code style

Use the @passlock/browser library to remove a passkey from a user’s device:

import { Passlock } from "@passlock/browser";
// get this from your development tenancy settings
const tenancyId = "myTenancyId";
const passkeyId = "myPasskeyId";
const passlock = new Passlock({ tenancyId });
const result = await passlock.deletePasskey({ passkeyId });
if (result.success) {
// happy days
} else {
console.log(result.error.message);
}
Choose your code style

You can first delete a passkey from your vault, then pass the result to your frontend code…

import { Passlock } from "@passlock/server";
const passlock = new Passlock({ tenancyId, apiKey });
const result = await passlock.deletePasskey({ passkeyId });
if (result.success) {
// send the DeletedPasskey payload to your frontend
res.send(JSON.stringify(result.value));
}
Choose your code style
import { Passlock } from "@passlock/browser";
const passlock = new Passlock({ tenancyId });
// result of calling deletePasskey in your backend
const backendDeletionResult = {
deleted: { credentialId: "...", userId: "...", rpId: "..." },
};
const result = await passlock.deletePasskey(backendDeletionResult.deleted);
if (!result.success) {
console.error(result.error.message);
}
Choose your code style

During client side authentication, if you receive an OrphanedPasskeyError, pass that error into the deletePasskey function:

import {
Passlock,
isOrphanedPasskeyError,
} from "@passlock/browser";
const passlock = new Passlock({ tenancyId });
const result = await passlock.authenticatePasskey(options);
if (result.failure && isOrphanedPasskeyError(result.error)) {
if (confirm("Passkey invalid, remove it?")) {
const deletion = await passlock.deletePasskey(result.error);
if (!deletion.success) {
console.error(deletion.error.message);
}
}
} else if (!result.success) {
console.error(result.error.message);
}
Choose your code style