lucia_middleware
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.
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:
- 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. RememberResponse.redirect
is broken in Val Town right now, so either use links orreturn new Response(null, { 302, headers: { Location: "/place/to/redirect" }})
- In your HTTP handler, read the
X-Lucia-Username
header, ieconst 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
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.
- 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