ComplicatedAuth
Menu

Integrate / SDK reference

SDK API reference.

Public classes, methods, options, return types, errors, storage contracts, and camera helpers for the three TypeScript packages.

Browser package

@complicatedauth/browser

Framework-neutral browser client. It communicates only with a same-origin BFF and never accepts a Project service credential.

new ComplicatedAuthClient(options)

OptionTypeMeaning
baseUrlstringRequired BFF mount path, typically /api/auth.
storageStorageLikeDefaults to sessionStorage, or memory outside a browser.
fetchtypeof fetchOptional transport injection for tests or runtimes.
storageKeyPrefixstringDefaults to complicatedauth.

Methods

MethodReturnsBehavior
startLogin(email)Promise<LoginAttempt>Creates a non-enumerating login attempt and stores its browser token.
startPasswordAuth(password)Promise<AuthProgress>Verifies the password. Returns factor_verified, or authenticated only when policy permits a completed session.
startPasskeyAuth()Promise<AuthenticatedSession>Runs a platform-passkey WebAuthn ceremony for the current login attempt.
startSecurityKeyAuth()Promise<AuthenticatedSession>Runs a cross-platform security-key ceremony.
startHybridAuth()Promise<AuthenticatedSession>Runs a hybrid/phone-assisted WebAuthn ceremony.
startFirstPasskeyEnrollment()Promise<AuthenticatedSession>After password verification, enrolls the user's first passkey and completes login.
startFirstSecurityKeyEnrollment()Promise<AuthenticatedSession>After password verification, enrolls the user's first attested security key and completes login.
startPasskeyEnrollment()Promise<FidoCredential>Enrolls a platform passkey for the current session.
startSecurityKeyEnrollment()Promise<FidoCredential>Enrolls a cross-platform security key for the current session.
removeFidoCredential(uid)Promise<void>Deletes a passkey or security-key credential owned by the current user.
restoreSession()Promise<AuthenticatedSession | null>Introspects stored state. Clears and returns null for an invalid or expired session.
getSession()AuthenticatedSession | nullReturns the locally stored session without a network request.
logout()Promise<void>Revokes the backend session when present and always clears browser state.
cancelLogin()voidForgets the current login attempt without touching an authenticated session.
supportsWebAuthn()booleanReports basic browser WebAuthn support.
supportsWebAuthnAutofill()Promise<boolean>Reports conditional mediation/autofill support.
platformAuthenticatorAvailable()Promise<boolean>Reports whether a platform authenticator is available.

Core values

interface AuthenticatedSession {
  token: string;
  expiresAt: string;
  projectUser: ProjectUser;
}

interface ProjectUser {
  uid: string;
  email: string;
  email_verified: boolean;
  status: "active" | "disabled";
  passkey_count: number;
  created_at: string;
}

type AuthProgress =
  | { status: "factor_verified"; factor: "password"; expiresAt: string }
  | { status: "authenticated"; session: AuthenticatedSession };
requestPlugin() and acceptPluginSession() are public extension hooks for official packages. Application code normally should not call them directly.

Server package

@complicatedauth/server

ComplicatedAuthServer is a Web-standard request handler for BFF routes. It adds a scoped Project service credential, exchanges sensitive backend references for random browser tokens, and sets Cache-Control: no-store.

new ComplicatedAuthServer(options)

OptionTypeMeaning
backendUrlstringRequired ComplicatedAuth API origin.
projectUidstringRequired Project UUID.
serviceCredentialstringRequired expiring secret; keep it exclusively on the server.
storeReferenceStoreUse RedisReferenceStore in production. Defaults to memory for development.
fetchtypeof fetchOptional server transport injection.

handle(request): Promise<Response>

Mount the same handler for GET, POST, and DELETE beneath a route ending in /auth. Unknown paths return a structured 404 and unexpected handler failures return bff_error.

BFF routeBehavior
POST /login/startStart a login and replace the backend reference with a browser-safe token.
POST /login/passwordVerify the password factor for the current login token.
POST /login/fido/optionsReturn WebAuthn request options.
POST /login/fido/verifyVerify FIDO and exchange the resulting session reference.
POST /login/fido/enrollment/optionsBegin initial FIDO enrollment after password verification.
POST /login/fido/enrollment/verifyEnroll the first FIDO credential and exchange the completed session.
POST /login/biometricVerify a selfie through the configured biometric provider.
POST /enrollments/fido/optionsBegin authenticated FIDO enrollment.
POST /enrollments/fido/verifyFinish authenticated FIDO enrollment.
DELETE /enrollments/fido/:uidDelete the current user's FIDO credential.
POST|DELETE /enrollments/biometricCreate, replace, or delete facial enrollment.
GET /sessionRestore and introspect a browser session.
POST /logoutRevoke the server session and forget the browser token.

ReferenceStore

interface ReferenceStore {
  get(token: string): Promise<StoredReference | null>;
  set(token: string, value: StoredReference): Promise<void>;
  delete(token: string): Promise<void>;
}

interface StoredReference {
  kind: "login" | "session";
  reference: string;
  expiresAt: string;
}

RedisReferenceStore accepts the official Redis client's get, set(..., {PX}), and del methods. It uses the backend expiry as the Redis TTL, rejects malformed records, and supports multiple BFF instances.

Biometric package

@complicatedauth/biometrics

Optional browser extension that uploads an image through the core client's authenticated plugin transport.

APIReturnsBehavior
new BiometricClient({client, maxSelfieBytes?})BiometricClientDefaults the image limit to 5 MiB.
startBiometricAuth(selfie)Promise<AuthenticatedSession>Requires an active login attempt and verified password policy.
startBiometricEnrollment(selfie)Promise<BiometricEnrollment>Creates or replaces enrollment for the authenticated user.
removeBiometricEnrollment()Promise<void>Deletes current enrollment.
startSelfieCamera(video, constraints?)Promise<MediaStream>Requests the front camera, attaches it, and starts playback.
captureSelfie(video, options?)Promise<Blob>Mirrors and encodes the current frame; defaults to JPEG, 0.9 quality, 1280 px.
stopSelfieCamera(videoOrStream)voidStops every media track and detaches the video element.
This package validates file type and size, not liveness. The deployment must define provider assurance, consent, retention, retry, and fallback policies.

Failure model

ComplicatedAuthError

Browser operations reject with ComplicatedAuthError when the failure comes from API, network, state, or WebAuthn handling.

PropertyTypeMeaning
kind"api" | "network" | "state" | "webauthn"Stable failure category for UI branching.
codestringAPI error code or SDK code such as login_not_started.
statusnumber?HTTP status when an API response exists.
causeunknown?Original network or WebAuthn error where available.
try {
  await auth.startPasskeyAuth();
} catch (error) {
  if (error instanceof ComplicatedAuthError) {
    report(error.kind, error.code, error.status);
  }
}

Search guides, architecture, SDKs, and the REST API.