Skip to main content
@glinr/theauth-svelte provides reactive Svelte stores for sessions and agents. It works with Svelte 4+, SvelteKit, and plain Vite setups.

Installation

Setup

Create a client instance once and export its stores from a shared module:
src/lib/theauth.ts
The client fetches the session from your theAuth handler in the browser. There is no SvelteKit hooks helper in this package, so locals.session is not populated for you. To mount the server routes, use the SvelteKit adapter (@glinr/theauth-sveltekit).

Session store

session holds the session object or null. user and isAuthenticated are derived from it, and isLoading is true until the first fetch settles.
src/routes/+page.svelte

Sign in, sign up, sign out

signIn and signUp take positional arguments and resolve to { success: true, data } or { success: false, error }, where error is a string.
src/routes/sign-in/+page.svelte
Sign up and sign out

createAgentStore

Manage agent identities in reactive Svelte stores. Pass the user store from your client and the agent list loads when a user is present, or call load(userId) yourself.
The store also exposes rotate(agentId).

Client configuration reference

string
default:"'/api/theauth'"
Base path where your theAuth handler is mounted.
RefetchOptions
Refetch the session on window focus, reconnect or an interval. Runs while any of the client’s stores has a subscriber. See Session refetch and SSR.
HydrateInput | null
Session the server already resolved. Skips the first request. Also available later as client.hydrateSession(initial).
boolean
default:"false"
Use the core email and password routes (/auth/email/sign-in, /auth/email/sign-up, body field email). Needs the emailPassword config on the server, see Email and password. signUp then resolves to data.verificationRequired, and the context also exposes verifyEmail, resendVerification, requestPasswordReset and resetPassword. Failed results carry the server code, for example EMAIL_NOT_VERIFIED.
string
default:"'/auth/username/sign-in'"
Route for signIn (/auth/email/sign-in with emailPassword). The username routes are not served by createTheAuthHandler: forward them with theauth.username.handleRequest.
string
default:"'/auth/username/sign-up'"
Route for signUp (/auth/email/sign-up with emailPassword).
string
default:"'username'"
Body field that carries the first argument of signIn and signUp (email with emailPassword).
On creation the client shows a stored session at once, then confirms it with GET {basePath}/auth/session. signOut clears local state first, then calls POST {basePath}/auth/sign-out. client.destroy() stops the refetch triggers and aborts an in-flight refresh.

SvelteKit adapter

Server-side theAuth handler for SvelteKit routes and hooks.

Vue

Composables and plugin for Vue 3 and Nuxt setups.

React

Hooks and provider component for React and Next.js.

Client SDK

Framework-agnostic fetch client underlying all framework SDKs.
Last modified on October 19, 2026