npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@classic-homes/auth

v0.1.23

Published

Authentication services and Svelte bindings for Classic Theme apps

Downloads

1,901

Readme

@classic-homes/auth

Framework-agnostic authentication core with Svelte bindings for the Classic Theme design system.

Features

  • JWT-based authentication with automatic token refresh
  • SSO (Single Sign-On) support with configurable providers
  • Multi-factor authentication (MFA/TOTP) support
  • Pluggable storage adapter (localStorage, sessionStorage, or custom)
  • Svelte reactive stores for authentication state
  • Route guards for protected pages
  • TypeScript-first with full type safety

Installation

npm install @classic-homes/auth

Quick Start

1. Initialize Authentication

In your app's entry point (e.g., hooks.client.ts for SvelteKit):

import { initAuth } from '@classic-homes/auth';

initAuth({
  baseUrl: 'https://api.example.com',
  storage: {
    getItem: (key) => localStorage.getItem(key),
    setItem: (key, value) => localStorage.setItem(key, value),
    removeItem: (key) => localStorage.removeItem(key),
  },
  onAuthError: (error) => {
    console.error('Auth error:', error);
  },
});

2. Use the Auth Store (Svelte)

<script lang="ts">
  import { authStore, authActions } from '@classic-homes/auth/svelte';

  async function handleLogin() {
    await authActions.login({
      email: '[email protected]',
      password: 'password123',
    });
  }

  async function handleLogout() {
    await authActions.logout();
  }
</script>

{#if $authStore.isAuthenticated}
  <p>Welcome, {$authStore.user?.email}</p>
  <button onclick={handleLogout}>Logout</button>
{:else}
  <button onclick={handleLogin}>Login</button>
{/if}

3. Protect Routes

// src/routes/dashboard/+page.ts
import { authGuard } from '@classic-homes/auth/svelte';

export const load = authGuard({
  redirectTo: '/login',
});

API Reference

Core Exports

import {
  // Initialization
  initAuth,
  getAuthConfig,

  // Service
  authService,
  AuthService,

  // API
  authApi,

  // Types
  type User,
  type AuthTokens,
  type LoginCredentials,
  type RegisterData,
  type AuthConfig,
} from '@classic-homes/auth';

Svelte Exports

import {
  // Store
  authStore,
  isAuthenticated,
  currentUser,

  // Actions
  authActions,

  // Guards
  authGuard,
  roleGuard,
} from '@classic-homes/auth/svelte';

Configuration Options

interface AuthConfig {
  /** Base URL for the auth API */
  baseUrl: string;

  /** Storage adapter for tokens */
  storage?: {
    getItem: (key: string) => string | null;
    setItem: (key: string, value: string) => void;
    removeItem: (key: string) => void;
  };

  /** SSO configuration */
  sso?: {
    enabled: boolean;
    provider: string;
    authorizeUrl?: string;
    tokenUrl?: string;
  };

  /** Callback when auth errors occur */
  onAuthError?: (error: Error) => void;

  /** Custom headers for API requests */
  headers?: Record<string, string>;
}

Auth Actions

The authActions object provides methods for authentication operations:

// Login with email/password
await authActions.login({ email, password, rememberMe });

// Register new user
await authActions.register({ email, password, fullName });

// Logout
await authActions.logout();

// Refresh session
await authActions.refreshSession();

// Change password
await authActions.changePassword({ currentPassword, newPassword });

// MFA operations
await authActions.verifyMfa({ code, trustDevice });
await authActions.setupMfa({ secret, code });
await authActions.disableMfa({ password });

// SSO
await authActions.initiateSSO();
await authActions.handleSSOCallback(code);

Auth Store State

interface AuthState {
  user: User | null;
  tokens: AuthTokens | null;
  isAuthenticated: boolean;
  isLoading: boolean;
  error: string | null;
  mfaRequired: boolean;
  mfaToken: string | null;
}

Route Guards

Basic Auth Guard

import { authGuard } from '@classic-homes/auth/svelte';

export const load = authGuard({
  redirectTo: '/login',
  returnUrl: true, // Append ?returnUrl= to redirect
});

Role-Based Guard

import { roleGuard } from '@classic-homes/auth/svelte';

export const load = roleGuard({
  roles: ['admin', 'manager'],
  redirectTo: '/unauthorized',
});

Using with @classic-homes/theme-svelte

The auth package integrates with the form validation from @classic-homes/theme-svelte:

<script lang="ts">
  import { useForm, loginSchema } from '@classic-homes/theme-svelte';
  import { authActions } from '@classic-homes/auth/svelte';

  const form = useForm({
    schema: loginSchema,
    initialValues: {
      email: '',
      password: '',
      rememberMe: false,
    },
    onSubmit: async (data) => {
      await authActions.login(data);
    },
  });
</script>

<form onsubmit={form.handleSubmit}>
  <input bind:value={form.data.email} />
  {#if form.errors.email}
    <span class="error">{form.errors.email}</span>
  {/if}
  <!-- ... -->
</form>

License

MIT