Linking accounts
During the passkey registration flow, we recommended you link the authenticatorId (passkey id) to a local user account. The Principal also includes a userId property, This defaults to the authenticator/passkey id:
{ "authenticatorId": "spy28n0bqca11tq", "userId": "spy28n0bqca11tq"}The passkey userId can be changed to align with your own internal userId. There are some benefits to doing so:
- It avoids the need for a User <-> Passkey join table on your side
- You can identify a passkey by meaningful user ID in the Passlock console
- You can perform operations on multiple passkeys assigned to the same user ID
Assigning a custom user ID
Section titled “Assigning a custom user ID”The Principal.userId can be changed via the @passlock/server package.
import { assignUser } from "@passlock/server";
const passkeyId = "myPasskeyId";const userId = "myInternalUserId";
const result = await assignUser({ userId, passkeyId }, { tenancyId, apiKey });
if (result.success) { console.log(result.value.userId);}If you reassign the userId to align with your own internal user IDs, you can use this property to look up local user accounts:
import { exchangeCode } from "@passlock/server";
const result = await exchangeCode({ code }, { tenancyId, apiKey });
if (result.success) { console.log(result.value);}{ "authenticatorId": "spy28n0bqca11tq", "userId": "myInternalUserId"}Using the console
Section titled “Using the console”Custom user IDs can also be assigned through your Passlock console.