FeaturesTemplatesShowcaseTownie
AI
BlogDocsPricing
Log inSign up
tsuchi_ya
tsuchi_yaluciaMagicLinkStarter
Remix of stevekrouse/luciaMagicLinkStarter
Public
Like
luciaMagicLinkStarter
Home
Code
3
backend
3
frontend
3
README.md
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 miliseconds.
Sign up now
Code
/
README.md
Code
/
README.md
Search
…
README.md

Lucia Auth Starter

A demonstration of Lucia, the guide, and magic link authentication using Val Town.

This uses Val Town SQLite and Val Town Email, so you can Remix & roll-your-own-auth in a single-click. Literally zero set up required.

Note: Sending emails to users besides yourself requires Val Town Pro.

Features

  • Magic link authentication
  • Server-side rendering with client-side hydration
  • User profile management (username editing)
  • Session management with secure cookies
  • Responsive UI with Tailwind CSS

Authentication Flow

  1. User enters their email address on the login page
  2. A magic link is sent to the user's email
  3. User clicks the magic link in their email
  4. The server validates the token, creates a session, and sets a secure cookie
  5. User is redirected to the authenticated home page

Technical Implementation

  • Database:Val Town SQLite for storing users, sessions, and magic link tokens
  • Frontend: React with Tailwind CSS
  • Backend: Hono.js for API routes and middleware
  • Authentication: Built by following the Lucia guide

API Endpoints

Provided by the Auth Middleware in backend/auth.ts:

  • POST /auth/magic-link - Request a magic link
  • GET /auth/magic-link/:token - Validate a magic link token
  • POST /auth/logout - Log out the current user

In the app's API, in backend/index.ts:

  • POST /api/user/username - Update the user's username

Notes

  • Email sending requires Val Town Pro subscription for sending to addresses other than your own
  • Magic links expire after 15 minutes
  • Session tokens are automatically rotated when 50% of their lifetime remains (15 days)
  • Sessions expire after 30 days

Todos

  • When I tried to make the magic link token single-use, it caused issues. I think the best practice there is something a bit more complicated, ie a GET request to an HTML page that makes a POST request.
  • When I tried to make the SameSite=Strict, the cookie stopped working. It's currently Lax, which I think is OK, but it'd be nice to know Strict isn't working.
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.