Public
Like
7
luciaMagicLinkStarter
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.
Viewing readonly version of main branch: v112View latest version
A demonstration of magic link authentication using Val Town.
- Magic link authentication
- Server-side rendering with client-side hydration
- User profile management (username editing with validation)
- Session management with secure cookies and token rotation
- Responsive UI with Tailwind CSS
- User enters their email address on the login page
- A magic link is sent to the user's email
- User clicks the magic link in their email
- The server validates the token, creates a session, and sets a secure cookie
- User is redirected to the authenticated home page
- Database: SQLite for storing users, sessions, and magic link tokens
- Frontend: React with Tailwind CSS
- Backend: Hono.js for API routes and middleware
- Authentication: Custom implementation with secure cookies
- Session Security: Sliding + rotating sessions (new token generated when 50% of session lifetime remains)
- Input Validation: Username validation enforces 3-50 printable characters and prevents XSS
POST /auth/magic-link
- Request a magic linkGET /auth/magic-link/:token
- Validate a magic link tokenPOST /auth/logout
- Log out the current userPOST /api/user/username
- Update the user's username
- Email sending requires Val Town Pro subscription for sending to addresses other than your own
- Magic links expire after 15 minutes
- Sessions expire after 30 days
- Session tokens are automatically rotated when 50% of their lifetime remains (15 days)
- Username validation rules: 3-50 printable characters, no "</>" sequences to prevent XSS