JavaScript SDK

Passkeys

Sign in with a passkey, register one for the signed-in user, list and remove them.

Passkeys use WebAuthn. They need the app setting passkeys_enabled: true (a missing value counts as off) and a secure page: https, or localhost while developing.

Check support#

import { passkeysAvailable } from "@scute/js-core";scute.isWebauthnSupported(); // the browser has WebAuthnpasskeysAvailable();         // WebAuthn and a secure context

Sign in#

signInOrUp and signIn use a passkey when the user has one and this device holds one of their credentials. To force it:

const result = await scute.signInWithVerifyDevice("ada@example.com");
ResultMeaning
{ error: null }Signed in. webauthn_verify_start, webauthn_verify_success and signed_in fire.
{ data: { mfaRequired: true, ... } }The app wants MFA after the passkey.
{ error: NewDeviceError }This device has no credential for the user. signInOrUp sends a link or a code instead.
{ error: IdentifierNotRecognizedError }Unknown identifier.
{ error: WebAuthnError }The prompt failed or was cancelled. error.code is one of the ERROR_* codes in Errors.

Register a passkey#

For a signed-in user:

const { data, error } = await scute.addDevice(); // opens the browser prompt

During a sign-in, after a link or code, register before the session starts:

const { data } = await scute.verifyMagicLinkToken(token);if (data && "authPayload" in data && !("signedIn" in data)) {  await scute.signInWithRegisterDevice(data.authPayload);}

webauthn_register_start and webauthn_register_success fire. On a page that cannot make passkeys (http, or a browser without WebAuthn) registration returns PasskeysUnavailableError (ERROR_PASSKEYS_UNAVAILABLE).

isAnyDeviceRegistered() returns true when this device holds a credential for the signed-in user. It throws LoginRequiredError when nobody is signed in.

Remove a passkey#

await scute.removeDeviceCredential(credentialId);

The user's sessions list each session's credential_id; revoking such a session with revokeSession(id) also forgets the credential on this device.

Lower-level calls#

MethodDoes
webauthnInitializeLogin(identifier)POST /webauthn/login/initialize: returns { options }.
webauthnFinalizeLogin({ publicKey })Opens the prompt and sends the assertion. Returns a token payload or a sign-in step.
webauthnInitializeRegister(accessToken)POST /devices/register: returns { options }.
webauthnFinalizeRegister({ publicKey }, accessToken)Opens the prompt and sends the attestation.