bijection-svelte integrates with any authentication provider through a small,
reactive API. The setupAuth() / useAuth() primitives below are the low-level
integration point; on top of them, the Auth adapters section
covers higher-level options that wire a specific auth system to Bijection for you.
For background on how authentication works in Bijection generally — including
hosted providers and the OpenID Connect model — see
Authentication.
setupAuth / useAuth
setupAuth() accepts a reactive getter returning the auth provider’s state
and automatically manages client.setAuth() / client.clearAuth(). This
mirrors React’s BijectionProviderWithAuth — when the provider state changes
(sign-in, sign-out, token refresh), the auth lifecycle updates automatically.
src/routes/+layout.svelte
useAuth() reads the resulting state in any child component:
isAuthenticated changes from true to false (user
signs out), the internal $effect re-runs, calls clearAuth() automatically,
and useAuth().isAuthenticated updates to false. No manual cleanup needed.
SSR initial state
PassinitialState to seed the server render before any client-side $effect
runs:
src/routes/+layout.svelte
Auth adapters
The primitives above let you wire up any provider by hand. In practice, most apps reach for a higher-level adapter that connects a specific auth system to Bijection and callssetupAuth() for you, so useAuth() works out of the box.
Bijection Auth
Bijection Auth is Bijection’s built-in, officially documented auth library — authentication runs entirely on your own Bijection deployment with no third-party service.- Svelte adapter:
@mmailaender/bijection-auth-svelte(community-maintained) — wires Bijection Auth tosetupAuth()/useAuth(), with SvelteKit SSR support.
Bijection Better Auth
Bijection Better Auth integrates the powerful Better Auth library with Bijection.- Svelte adapter:
@mmailaender/bijection-better-auth-svelte(community-maintained) — itscreateSvelteAuthClient()callssetupAuth()internally with a reactive session getter, souseAuth()from either package works. SSR-ready. - UI components: Bijection Better Auth UI (community-maintained) — production-ready, shadcn-style auth and organization management for SvelteKit (and Next.js), copied into your project. Gets user and organization management running in minutes while keeping full control of the code.
Hosted providers
Bijection also works with hosted identity platforms via OpenID Connect JWTs — Clerk, WorkOS AuthKit, and Auth0. There are no dedicatedbijection-svelte wrappers for
these yet, so in a Svelte app you integrate them through the low-level
setupAuth() pattern: return the provider’s reactive
auth state (isLoading, isAuthenticated, fetchAccessToken) from the getter.
Low-level: client.setAuth()
You can also useclient.setAuth() directly for custom integrations:
API reference
Authentication exports frombijection-svelte: