Skip to content

Linking local user accounts

During the passkey registration flow, we recommended you link the authenticatorId (passkey id) to a local user account.

You may have noticed that the Principal also includes a userId property, which mirrors the authenticatorId. During passkey registration the userId defaults to the authenticatorId because, from a Passlock perspective we dont know anything about the user at this stage. All we know is that someone created a passkey:

{
"authenticatorId": "spy28n0bqca11tq",
"userId": "spy28n0bqca11tq"
}

The Principal.userId can be changed via a backend REST call.

backend.ts
import { assignUserUnsafe } from "@passkey/server/authenticator";
const userId = "myInternalUserId";
await assignUserUnsafe({ userId, authenticatorId, tenancyId, apiKey });

If you reassign the userId to align with your own internal user ids, you can use this property to lookup local user accounts:

backend.ts
const principal = await exchangeCode(code, { tenancyId, apiKey });
console.log(pricipal);
{
"authenticatorId": "spy28n0bqca11tq",
"userId": "myInternalUserId"
}