FeaturesTemplatesShowcaseTownie
AI
BlogDocsPricing
Log inSign up
stevekrouse
stevekrouselucia_middleware
Remix of stevekrouse/lucia_demo
Public
Like
2
lucia_middleware
Home
Code
2
README.md
main.tsx
Branches
1
Pull requests
Remixes
1
History
Environment variables
Settings
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in miliseconds.
Sign up now
Code
/
Code
/
Search
README.md

Lucia Middleware

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:

Create val
import { luciaMiddleware } from "https://esm.town/v/stevekrouse/lucia_middleware_safe";

Usage

  1. Wrap your HTTP handler in it, ie export default luciaMiddleware(handler)
  2. 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" }})
  3. In your HTTP handler, read the X-Lucia-Username header, ie const username = req.headers.get("X-Lucia-Username")
  4. 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.

Todos

  • Allow users to specify the users & sessions table
  • Remove Hono from this middleware (attempted in this fork: @stevekrouse/lucia_middleware_vanilla)
  • Allow users to customize the auth pages without forking the middleware

Initially built by @pomdtr

Migrated from folder: Archive/lucia_middleware

Code
README.mdmain.tsx
Go to top
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Product
FeaturesPricing
Developers
DocsStatusAPI ExamplesNPM Package Examples
Explore
ShowcaseTemplatesNewest ValsTrending ValsNewsletter
Company
AboutBlogCareersBrandhi@val.town
Terms of usePrivacy policyAbuse contact
© 2025 Val Town, Inc.