Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Readme

Lucia Middleware Demo

Import users. Backed by Val Town SQLite.

Initially built by @pomdtr.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/** @jsxImportSource npm:hono@3/jsx */
import { luciaMiddleware } from "https://esm.town/v/stevekrouse/lucia_middleware";
import type { Session, User } from "lucia";
import { Hono } from "npm:hono";
const app = new Hono();
app.get("/", (c) => {
const username = c.req.header("X-Lucia-Username");
if (username) {
return c.html(
<div>
<h1>Welcome, {username}!</h1>
<a href="/auth/logout">Logout</a>
</div>,
);
} else {
return c.html(
<div>
<h1>Welcome to the App</h1>
<p>Please sign in to continue.</p>
<p>
<a href="/auth/login">Sign In</a>
</p>
<p>
<a href="/auth/signup">Sign Up</a>
</p>
</div>,
);
}
});
export default luciaMiddleware(app.fetch);
stevekrouse-lucia_middleware_demo.web.val.run
August 9, 2024