Skip to content

Overview

@authrim/sveltekit is a full-stack authentication SDK for SvelteKit applications. It wraps Authrim’s browser and core protocol clients with SvelteKit-specific integrations — server-mediated Direct Auth sessions, server hooks, Svelte stores, pre-built components, page templates, handoff SSO helpers, and tenant discovery.

flowchart TB
    subgraph Server ["Server (hooks.server.ts)"]
        direction LR
        Handle["createAuthHandle()"]
        SSM["ServerSessionManager"]
        Load["requireAuth() /<br>createAuthLoad()"]
    end

    subgraph Client ["Client (Browser)"]
        direction LR
        Auth["AuthrimClient"]
        Stores["Svelte Stores"]
        Components["Components"]
        UI["UI Library"]
    end

    subgraph Core ["@authrim/core"]
        direction LR
        CoreAuth["OIDC / OAuth"]
        CoreCrypto["PKCE / WebAuthn"]
    end

    Handle --> SSM
    SSM --> Load
    Load -->|SSR data| Auth
    Auth --> Stores
    Auth --> Core
    Stores --> Components
    Components --> UI
Export PathPurposeExample Imports
@authrim/sveltekitClient entry — factory, types, context, tenant discoverycreateAuthrim, AuthrimClient, AuthStores, TenantDiscoveryClient
@authrim/sveltekit/serverServer hooks, session handlers, load helpers, handoff SSOcreateAuthHandle, createDirectAuthSessionHandlers, requireAuth, createAuthLoad, verifyHandoffToken, createHandoffHandler
@authrim/sveltekit/storesStore factory (advanced)createAuthStores
@authrim/sveltekit/componentsCore Svelte componentsAuthProvider, ProtectedRoute, SignInButton
@authrim/sveltekit/uiFull UI component libraryButton, Input, EmailCodeForm, PasskeyList
@authrim/sveltekit/ui/stylesTheme CSSimport '@authrim/sveltekit/ui/styles'
@authrim/sveltekit/ui/templatesPage templatesLoginTemplate, ConsentTemplate

AuthrimClient exposes authentication features through namespaces:

NamespaceMethodsPurpose
auth.passkeylogin(), signUp(), register(), isSupported()WebAuthn passkey authentication
auth.emailCodesend(), verify(), hasPendingVerification()Email OTP authentication
auth.socialloginWithPopup(), loginWithRedirect(), handleCallback()Social provider authentication
auth.sessionget(), validate(), refresh(), isAuthenticated(), getUser(), clearCache()Session management
auth.consentgetData(), submit()OAuth consent screen
auth.deviceFlowsubmit()Device authorization (RFC 8628)
auth.cibagetData(), approve(), reject()CIBA flow
auth.loginChallengegetData()Login challenge screen
auth.stepUpstart(), getAction(), complete(), resend(), cancel()Canonical Step-Up actions
auth.customerProfilesgetWithElevationGrant(), updateDelegated()Customer profile protected resource API
auth.deviceslist(), rename(), unlink()Self-service device inventory
auth.signInpasskey(), social()Shortcut methods
auth.signUppasskey()Shortcut methods
auth.signOut()Sign out with optional redirect
auth.fetch()Profile-aware fetch helper for cookie-session and token-session API calls
auth.storessession, user, isAuthenticated, loadingState, errorReactive Svelte stores
auth.on()Event subscription
AspectDetails
Peer dependencysvelte ^4.0.0 || ^5.0.0
SDK internal syntaxSvelte 4 (export let, <slot>, on:event)
Your app codeUse Svelte 5 runes ($state(), $props(), $derived(), $effect())
CompatibilitySDK components work unchanged in Svelte 5 projects

This documentation uses Svelte 5 runes for all examples. See Configuration for a Svelte 4 syntax reference.

@authrim/sveltekit shares the same core authentication API as @authrim/web, but adds SvelteKit-specific features:

FeatureWeb SDKSvelteKit SDK
Authentication API✓ (same)
Server-mediated Direct Auth sessions
Server hooks / SSR
Svelte stores
Svelte components
UI library & templates
Smart Handoff SSO helpers
Tenant discovery helpers
SvelteKit routing integration

For authentication flow details (WebAuthn internals, email code mechanics, social login protocols), see the Web SDK documentation.