• Townie
    AI
  • Blog
  • Docs
  • Pricing
  • We’re hiring!
Log inSign up
mrsnor

mrsnor

cooingTomatoSquirrel

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

LastLogin Authentication

Add user auth to your app via LastLogin. LastLogin is a hosted auth provider that enables login through email, Google, Github, etc.

How to setup

These instructions were written to be easily copy-and-pasteable into LLMs like Townie.

  1. import { lastlogin } from "https://esm.town/v/stevekrouse/lastlogin_safe";
  2. Wrap your HTTP handler in it, ie export default lastLogin(handler)
  3. In your handler, redirect to /auth/login or /auth/logout to trigger those flows.
  4. In your HTTP handler, read the X-LastLogin-Email header, ie const email = req.headers.get("X-LastLogin-Email")
  5. If the user is logged in, you now have a email you can work with. If not, it will be empty

Screenshot 2024-08-08 at 08.48.41.gif

Live demo

How it works:

  1. Your users click on a link to /auth/login in your app
  2. This middleware directs them to login via LastLogin
  3. They authenticate to LastLogin
  4. LastLogin redirects them back to your app
  5. This middleware "logs them in" to your app by giving them a session cookie.
  6. In your app, you can read the X-LastLogin-Email header to see which (if any) user is logged in

Notes

  • If you want username & password auth: @stevekrouse/lucia_middleware
  • This middleware stores sessions in the lastlogin_session table in your Val Town SQLite
  • This val has NOT been properly audited for security. I am not a security expert. I would suggest only using it for demos, prototypes, or apps where security is not paramount. If you are a security expert, I would appreciate your help auditing this!

Todos

  • Let the user customize the name of the SQLite table
  • Get a proper security audit for this
Code
README.mdmain.tsx
FeaturesVersion controlCode intelligenceCLI
Use cases
TeamsAI agentsSlackGTM
ExploreDocsShowcaseTemplatesNewestTrendingAPI examplesNPM packages
PricingNewsletterBlogAboutCareers
We’re hiring!
Brandhi@val.townStatus
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Terms of usePrivacy policyAbuse contact
© 2025 Val Town, Inc.