/** * Auth Store * * Client-side authentication state management using Svelte 5 runes. * Provides reactive user state and auth operations. * * Canon: One identity, many manifestations. The store disappears; only the user remains. * * @packageDocumentation */ import { type Readable } from 'svelte/store'; import { type User } from '../index.js'; export interface AuthState { user: User | null; isAuthenticated: boolean; isLoading: boolean; error: string | null; } export interface AuthStoreConfig { /** Identity worker endpoint (defaults to SESSION_CONFIG.IDENTITY_ENDPOINT) */ identityEndpoint?: string; /** Analytics tracking options */ analytics?: { property: 'io' | 'space' | 'agency' | 'ltd' | 'lms'; getSessionId: () => string; trackEvent: (event: unknown) => void; }; /** Callback after successful login */ onLoginSuccess?: (user: User) => void; /** Callback after logout */ onLogoutSuccess?: () => void; /** Callback on auth error */ onError?: (error: string) => void; } export interface LoginCredentials { email: string; password: string; } export interface SignupCredentials { email: string; password: string; name?: string; source?: 'io' | 'space' | 'agency' | 'ltd' | 'lms'; } export interface MagicLinkRequest { email: string; source?: 'io' | 'space' | 'agency' | 'ltd' | 'lms'; } /** * Create an auth store for client-side auth management * * @example * ```typescript * // In +layout.svelte * import { createAuthStore } from '@create-something/components/auth/components'; * * const auth = createAuthStore({ * analytics: { * property: 'space', * getSessionId: () => sessionId, * trackEvent: (e) => track(e) * } * }); * * // In components * {#if $auth.isAuthenticated} * auth.logout()} /> * {:else} * auth.login(creds)} /> * {/if} * ``` */ export declare function createAuthStore(config?: AuthStoreConfig): { subscribe: (this: void, run: import("svelte/store").Subscriber, invalidate?: () => void) => import("svelte/store").Unsubscriber; login: (credentials: LoginCredentials) => Promise; signup: (credentials: SignupCredentials) => Promise; sendMagicLink: (request: MagicLinkRequest) => Promise; logout: () => Promise; refresh: () => Promise; initialize: (user: User | null) => void; user: Readable; isAuthenticated: Readable; isLoading: Readable; error: Readable; }; /** * Get or create a default auth store instance */ export declare function getAuthStore(config?: AuthStoreConfig): ReturnType;