Choose your code style
Each developer or team has a preferred coding style. The Passlock client libraries therefore expose multiple entry points. They are functionally equivalent, choose the entrypoint that best fits your style.
Class based API
Section titled “Class based API”Instantiate a Passlock instance, providing the config, then call methods on that instance. The methods don’t throw for expected errors, they return an Result wrapper encompassing the success and error paths. Use the success proprty to narrow the type:
import { Passlock, isPasskeyUnsupportedError } from "@passlock/browser";
const passlock = new Passlock({ tenancyId });
const result = await passlock.authenticatePasskey({ ... });
if (result.success) { console.log(result.value);} else { console.log(result.error);
// narrow the error if (isPasskeyUnsupportedError(result.error)) { console.log("Passkeys are not supported"); }
// alternatively narrow using the _tag discriminator if (result.error._tag === "@error/PasskeyUnsupported") { console.log("Passkeys are not supported"); }}Standalone functions
Section titled “Standalone functions”Import the function and provide the Passlock config as an argument. As with the safe class based approach, these functions don’t throw for expected errors:
import { authenticatePasskey } from "@passlock/browser";
// provide the config as the final argumentconst result = await authenticatePasskey({ ... }, { tenancyId });
if (result.success) { console.log(result.value);} else { ...}