Import users. Backed by Val Town SQLite.
Demo: @stevekrouse/lucia_middleware_demo
If you want a version that is safe to import (but not call) on the frontend:
import { luciaMiddleware }
from "https://esm.town/v/stevekrouse/lucia_middleware_safe";
- Wrap your HTTP handler in it, ie
export default luciaMiddleware(handler)
- In your handler, redirect to
/auth/signup
, /auth/login
, /auth/logout
to trigger those flows.
Remember Response.redirect
is broken in Val Town right now, so either use links or return new Response(null, { 302, headers: { Location: "/place/to/redirect" }})
- In your HTTP handler, read the
X-Lucia-Username
header, ie const username = req.headers.get("X-Lucia-Username")
- If the user is logged in, you now have a username you can work with. If not, it will be empty
Custom Sign Up and Log In pages
By default, the middleware has very basic sign in and sign up pages.
The only way to customize those right now is to fork this middleware and customize them to your liking.
Initially built by @pomdtr