FeaturesTemplatesShowcaseTownie
AI
BlogDocsPricing
Log inSign up
panphora

panphora

hyperclay

a single-tenant version of hyperclay
Public
Like
hyperclay
Home
Code
2
README.md
H
index.ts
Branches
1
Pull requests
Remixes
1
History
Environment variables
3
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
/
README.md
Code
/
README.md
Search
9/4/2025
Viewing readonly version of main branch: v5
View latest version
README.md

Hyperclay-Compatible Self-Updating Page

A simple, elegant implementation of a self-updating HTML page with email authentication, built for Val.town and fully compatible with Hyperclay.js.

Features

  • Email Authentication: Secure admin access via magic links
  • Hyperclay Integration: Full compatibility with Hyperclay.js editing features
  • Version History: Automatic versioning of all changes with viewing capability
  • Simple Architecture: Single file implementation, easy to understand and modify
  • Persistent Storage: Uses Val.town blob storage for reliability
  • Namespace Support: Environment-configurable for multiple deployments

Environment Variables

Set these in your Val.town environment:

  • ADMIN_EMAIL: The email address that can authenticate for edit access (required)
  • APP_NAMESPACE: Namespace for storage keys, allows multiple deployments (optional, defaults to "default")

URL Structure

Public URLs (No Authentication Required)

  • GET / - Serves the HTML document
  • GET/POST /auth/view - Switches to view mode (clears admin cookies)

Protected URLs (Email Authentication Required)

  • GET/POST /auth/edit - Email auth flow, sets admin cookies on success

Admin-Only URLs (Requires Admin Cookies)

  • POST /save/app - Saves HTML content (used by Hyperclay.js)
  • GET /versions - View version history of all saved documents

User Flows

Public User Experience

  1. Visit your Val.town URL
  2. See content in read-only mode
  3. No edit controls visible (handled by Hyperclay.js)

Admin Authentication Flow

  1. Visit /auth/edit
  2. Enter your email (must match ADMIN_EMAIL)
  3. Check email for magic link
  4. Click link → authenticated and redirected to main page
  5. Edit controls now visible and functional

Admin Editing Experience

  1. After authentication, visit main URL
  2. Hyperclay.js detects admin cookies
  3. Content becomes editable with edit-mode-* attributes
  4. Changes auto-save via Ctrl+S or periodic saves
  5. Visit /versions to see change history

Technical Implementation

Authentication Flow

  • Uses @pomdtr/email_auth for secure magic link authentication
  • Sets Hyperclay-compatible cookies (currentResource=app, isAdminOfCurrentResource=true)
  • Cookies expire after 30 days but extend on activity

Storage Strategy

  • Main document stored as {namespace}_app
  • Versions stored as {namespace}_app_version_{number}
  • Version counter stored as {namespace}_app_version_count
  • All storage uses Val.town blob storage for persistence

Hyperclay.js Integration

  • Loads Hyperclay.js from CDN (always latest version)
  • Follows standard Hyperclay patterns for edit mode detection
  • Supports all edit-mode-* attributes (contenteditable, show, onclick, etc.)
  • Auto-save posts to /save/app endpoint

Security Model

  • Email authentication gates admin cookie setting
  • Save endpoint validates admin cookies before accepting changes
  • No secrets exposed in client-side code
  • Version history only accessible to authenticated admins

Default HTML Template

The system starts with a Hyperclay starter template that includes:

  • Tailwind CSS integration
  • Hyperclay.js starter kit
  • Template selection interface
  • Dark theme styling
  • Responsive design

Development

Testing the Implementation

  1. Set your ADMIN_EMAIL environment variable
  2. Deploy to Val.town
  3. Visit your Val.town URL to see public view
  4. Visit /auth/edit to test authentication flow
  5. Make edits and verify auto-save functionality
  6. Check /versions to see version history

Customization

  • Modify DEFAULT_HTML to change the starting template
  • Adjust cookie expiration in editAuthHandler
  • Add additional validation in saveHTML if needed
  • Extend version history with metadata (timestamps, etc.)

Architecture Benefits

Simplicity

  • Single file implementation
  • No database setup required
  • Minimal configuration (just email)
  • Standard Hyperclay patterns

Reliability

  • Persistent blob storage
  • Automatic version history
  • Comprehensive error handling
  • Graceful degradation

Security

  • Email-based authentication
  • Cookie-based session management
  • No client-side secrets
  • Protected admin endpoints

Troubleshooting

Common Issues

  1. Can't authenticate: Check ADMIN_EMAIL environment variable matches exactly
  2. Changes not saving: Verify admin cookies are set (check browser dev tools)
  3. Version history empty: Versions are only created after first save
  4. Edit mode not working: Ensure Hyperclay.js is loading (check browser console)

Debug Steps

  1. Check browser cookies for isAdminOfCurrentResource=true
  2. Verify network requests to /save/app are successful
  3. Test authentication flow by visiting /auth/edit
  4. Check Val.town logs for server-side errors

This implementation provides a robust, secure, and user-friendly self-updating page system that integrates seamlessly with Hyperclay.js while maintaining simplicity and elegance.

FeaturesVersion controlCode intelligenceCLI
Use cases
TeamsAI agentsSlackGTM
ExploreDocsShowcaseTemplatesNewestTrendingAPI examplesNPM packages
PricingNewsletterBlogAboutCareersBrandhi@val.townStatus
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Terms of usePrivacy policyAbuse contact
Ā© 2025 Val Town, Inc.