lastlogin
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.
Live demo: https://stevekrouse-lastlogin_demo.web.val.run/ Source: @stevekrouse/lastlogin_demo
Wrap your http handlers in a lastlogin middleware (sessions will be persisted in the lastlogin_session
table on your sqlite account).
/** @jsxImportSource npm:hono@3/jsx */
import { lastlogin } from "https://esm.town/v/stevekrouse/lastlogin?v=5";
import { Hono } from "npm:hono";
const app = new Hono();
app.get("/", (c) => {
const email = c.req.header("X-LastLogin-Email");
if (email) {
return c.html(
<div>
<h1>Welcome, {email}!</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>
<a href="/auth/login">Sign In</a>
</div>
);
}
});
export default lastlogin(app.fetch);