Auth Types

Provider-agnostic interfaces for authentication and key derivation

The auth types are defined in @learncard/types (in src/auth.ts) and provide the abstract interfaces used by the AuthCoordinator, auth providers, and key derivation strategies.

Installation

pnpm add @learncard/types

Interfaces

AuthProvider

The interface that authentication providers must implement. Handles sign-in, sign-out, and token management.

interface AuthProvider {
    /** Get the provider type identifier (e.g., 'firebase') */
    getProviderType(): AuthProviderType;

    /** Get the currently authenticated user, or null */
    getCurrentUser(): Promise<AuthUser | null>;

    /** Get a fresh ID token for the current user */
    getIdToken(): Promise<string>;

    /** Sign out the current user */
    signOut(): Promise<void>;

    /** Subscribe to auth state changes. Returns an unsubscribe function. */
    onAuthStateChanged(callback: (user: AuthUser | null) => void): () => void;

    /** Re-authenticate with a custom token (e.g., after contact method upgrade) */
    reauthenticateWithToken?(token: string): Promise<void>;
}

AuthUser

Represents an authenticated user in a provider-agnostic way:

KeyDerivationStrategy

The interface that key derivation strategies must implement. Handles key generation, storage, reconstruction, and recovery.

ServerKeyStatus

The response from checking the server for an existing key record:

RecoveryMethodInfo

Information about a configured recovery method:

SignInAdapter

The interface for sign-in UI adapters (Phase 2 of auth abstraction). Handles the UI-layer sign-in methods:

AuthSessionError

Typed error class for authentication session issues:

Usage

These types are re-exported by both @learncard/sss-key-manager and learn-card-base for convenience.

Last updated

Was this helpful?