Authdog

SvelteKit

Authentication for 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.

One handle hook
Register createAuthdogHandle once and event.locals.authdog is populated on every request. No per-route setup.
No UI peer dependency
The handle and vanilla client bootstrap are framework-agnostic, so auth works across your whole app.
Session read per request
The cookie is parsed and verified in the handle before your route renders, so protected content never flashes.
Typed end to end
Augment App.Locals once and the session autocompletes in loads, form actions, and endpoints.

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

Everything SvelteKit apps need

A server handle and helpers that resolve sessions per request, with no UI-framework lock-in.

01

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
02

No UI-framework lock-in

A framework-agnostic handle plus a tiny vanilla client bootstrap means no extra peer dependency. It works across your whole SvelteKit app.

  • Zero UI peer dependencies
  • Works in every route
03

Server helpers

createAuthdogServer() resolves the full user on demand in +page.server.ts loads, form actions, and endpoints, and handles logout from a server route.

  • Loads and form actions
  • Server-side logout
04

Secure by default

Tokens are validated against the trusted identity host and sessions ride secure, HTTP-only cookies read only on the server, never the browser.

  • HTTP-only cookies
  • Tokens verified server-side
05

Typed locals

Augment App.Locals once and event.locals.authdog is fully typed across your loads, actions, and endpoints, with autocomplete for the session everywhere.

  • App.Locals augmentation
  • Autocomplete everywhere
06

SSR ready

Built for SvelteKit's SSR model so the handle reads the session cookie on every request before your route renders. No protected content flash.

  • No protected content flash
  • Edge and Node adapters
01

Install

Add @authdog/sveltekit and your environment's public key.

02

Wire the handle

Register createAuthdogHandle in src/hooks.server.ts, once.

03

Read the session

Branch on event.locals.authdog in loads, actions, and endpoints.

Add auth to your SvelteKit app.

Install the SDK, wire up the handle, and read the session from event.locals today. Free to start, with secure defaults built in.