Documentation
Docs
Introduction
Getting Started
Tutorial: build an app
Core Concepts
Routing
Server-Side Rendering
Mimir, state management
Pages & Layouts
API Routes
Styling & Theming
Building & Deploying
API Reference
Guides
Recipes
FAQ (use cases)
Recipe , authentication
A session-cookie auth flow in rune: middleware attaches the user to every request, the server seeds it into the page so components know who is logged in without a round-trip, and guarded routes redirect.
Permission: hashing passwords uses
ekko:crypto(pbkdf2), which needs thecryptopermission. Run an auth app withekko run server.tsx --allow=fs,net,env,crypto(theekko init runescaffold already adds"crypto": trueto itsekko.json). Without it the first hash throwsPermissionError: crypto access denied.
1. Middleware attaches req.user
Now every API handler and the SSR layer can read req.user. rune carries it into the page data as __user.
2. Login / logout API routes
Use HttpOnly cookies (JS cannot read them) with Secure + SameSite; never store the token where client
JS can exfiltrate it.
3. Seed the user into an auth atom
So components render the right state on first paint, hydrate __user into an atom. The cleanest path is to
read it during hydration; in app code you seed an auth atom from the server's req.user:
On a dynamic/shell route (not a cached static page), seed it per request:
Do not seed the user into a cached static page's
__atoms, the HTML is shared across users. Use a dynamic/shell route for authenticated pages, or render a neutral page and load the user after hydration viaGET /api/me. See Mimir → SSR & hydration.
4. Components read the user
(For in-app navigation use <Link>; here /login could be a real navigation either way.)
5. Guard authenticated routes
Two layers:
And reject unauthenticated API calls:
6. The GET /api/me pattern (for cached pages)
For pages that are cached and shared, render them neutral and fetch the user after hydration:
This keeps the cached HTML user-neutral while still personalising the UI once JS runs.
Security checklist
- [ ]
HttpOnly,Secure,SameSitecookies; tokens never readable by client JS. - [ ] Validate and authorize on the server in every protected API route (
req.usercheck). - [ ] Do not seed user data into cached static pages.
- [ ] Scope the app's permissions (
netonly to your auth/DB host, etc.). - [ ] Rotate/expire sessions server-side;
logoutdestroys the session.