@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
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 theuser store from your client and the agent list loads when a user is present, or call load(userId) yourself.
rotate(agentId).
Client configuration reference
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.
Session the server already resolved. Skips the first request. Also available later as
client.hydrateSession(initial).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.Route for
signIn (/auth/email/sign-in with emailPassword). The username routes are not served by createTheAuthHandler: forward them with theauth.username.handleRequest.Body field that carries the first argument of
signIn and signUp (email with emailPassword).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.
Related
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.