Session handle hook
Wire createAuthdogHandle once in hooks.server.ts and every request gets event.locals.authdog: a typed session resolved on the server, per request.
- One registration in hooks.server.ts
- Resolved before your route renders
SvelteKit
Add auth with a single handle hook, server helpers, and a tiny vanilla client bootstrap. No UI-framework peer dependency required: Authdog reads the session on the server, the way SvelteKit intends.
Session handle
// src/hooks.server.ts
import { createAuthdogHandle } from "@authdog/sveltekit/server"
export const handle = createAuthdogHandle({
publicKey: import.meta.env.PUBLIC_AUTHDOG_PUBLIC_KEY,
})
Read the session in a load
// src/routes/profile/+page.server.ts
import { createAuthdogServer } from "@authdog/sveltekit/server"
export const load = async ({ request, locals }) => {
const authdog = createAuthdogServer()
const user = locals.authdog.isAuthenticated
? await authdog.getUser(request)
: null
return { user: user?.user ?? null }
}
Built on web fundamentals
A server handle and helpers that resolve sessions per request, with no UI-framework lock-in.
Wire createAuthdogHandle once in hooks.server.ts and every request gets event.locals.authdog: a typed session resolved on the server, per request.
A framework-agnostic handle plus a tiny vanilla client bootstrap means no extra peer dependency. It works across your whole SvelteKit app.
createAuthdogServer() resolves the full user on demand in +page.server.ts loads, form actions, and endpoints, and handles logout from a server route.
Tokens are validated against the trusted identity host and sessions ride secure, HTTP-only cookies read only on the server, never the browser.
Augment App.Locals once and event.locals.authdog is fully typed across your loads, actions, and endpoints, with autocomplete for the session everywhere.
Built for SvelteKit's SSR model so the handle reads the session cookie on every request before your route renders. No protected content flash.
Add @authdog/sveltekit and your environment's public key.
Register createAuthdogHandle in src/hooks.server.ts, once.
Branch on event.locals.authdog in loads, actions, and endpoints.
Install the SDK, wire up the handle, and read the session from event.locals today. Free to start, with secure defaults built in.