Check that ADMIN_EMAIL is set to your exact email address
Enable DEBUG=true
Save your val to apply the changes
Step 2: Test Authentication Flow
Visit /auth/edit
Enter your email (must match ADMIN_EMAIL exactly)
Check Val.town logs for debug messages:
Look for "Auth email submission" log
Verify email matches admin email
Check for "Generated magic link token" log
Step 3: Check Email Delivery
Check your email inbox (including spam folder)
Look for email with subject "Sign in to your Hyperclay app"
If no email received, check Val.town logs for email sending errors
Step 4: Test Magic Link
Click the magic link in your email
Check Val.town logs for:
"Magic link verification attempt"
"Magic link token verification result"
"Creating session and redirecting"
You should be redirected to the main page
Step 5: Verify Session Creation
After clicking the magic link, check:
Browser cookies: Open DevTools → Application → Cookies
Look for session cookie (HttpOnly, so won't be visible in JS)
Look for isAdminOfCurrentResource=true cookie
Look for currentResource=app cookie
Step 6: Test Main Page Admin Status
Visit the main page (/)
Check Val.town logs for:
"Checking admin status"
"Session ID from cookie"
"Admin check result"
"Setting Hyperclay admin cookies" (if admin)
Step 7: Test Edit Functionality
Try to edit content on the page
Save changes (Ctrl+S)
Check Val.town logs for:
"Save endpoint accessed"
"Admin status for save endpoint"
"Save request details"
"HTML saved successfully"
Common Issues & Solutions
Issue: "isAdminOfCurrentResource" cookie not being set
Possible Causes:
Session not created: Magic link didn't work properly
Session expired: Check session expiry in logs
Email mismatch: Your email doesn't match ADMIN_EMAIL
Cookie header issues: Browser not sending session cookie
Debug Steps:
Check logs for "User admin status for main page" - should show isUserAdmin: true
Verify session cookie exists in browser
Check "Admin check result" log for email comparison
Try clearing all cookies and re-authenticating
Issue: Magic link not working
Possible Causes:
Token expired: Links expire after 15 minutes
Token already used: Magic links are one-time use
Email mismatch: Token was generated for different email
Debug Steps:
Check "Magic link token verification result" log
Look for "Auth token expired" or "Auth token invalid" messages
Generate a new magic link if token expired
Issue: Can't save edits
Possible Causes:
Not authenticated: Session invalid or expired
Wrong cookies: Hyperclay cookies not set properly
Network issues: Save requests not reaching server
Debug Steps:
Check "Admin status for save endpoint" log
Verify both session and Hyperclay cookies are present
Check browser Network tab for failed requests to /save/app
Issue: Authentication works but edit mode not visible
Possible Causes:
Hyperclay cookies missing: isAdminOfCurrentResource not set
Hyperclay.js not loading: Check browser console for errors
Cookie domain/path issues: Cookies not accessible to Hyperclay
Debug Steps:
Check browser cookies for isAdminOfCurrentResource=true
Open browser console and check for JavaScript errors
Verify Hyperclay.js is loading from CDN
Browser Debugging Tools
Check Cookies
Open DevTools (F12)
Go to Application → Cookies → [your-domain]
Look for:
session (HttpOnly - won't show value)
isAdminOfCurrentResource=true
currentResource=app
Check Network Requests
Open DevTools → Network tab
Try to save content (Ctrl+S)
Look for POST request to /save/app
Check request headers include cookies
Verify response is 200 OK with {"msg":"Saved"}
Check Console Errors
Open DevTools → Console
Look for JavaScript errors
Check if Hyperclay.js loaded successfully
Manual Testing Commands
Test Session Validation
Visit these URLs to test different states:
/auth/edit - Should show email form
/auth/view - Should clear session and redirect
/versions - Should show version history (admin only)
/save/app - Should return 401 if not authenticated
Test Cookie Behavior
Use browser DevTools to:
Delete all cookies
Re-authenticate
Verify cookies are set correctly
Test edit functionality
Debug Log Examples
Successful Authentication Flow
[DEBUG] Auth email submission {"userEmail":"admin@example.com","adminEmail":"admin@example.com"}
[DEBUG] Generated magic link token {"token":"12345678...","userEmail":"admin@example.com"}
[DEBUG] Magic link sent {"userEmail":"admin@example.com","origin":"https://yourval.web.val.run"}
[DEBUG] Magic link verification attempt {"token":"12345678..."}
[DEBUG] Magic link token verification result {"email":"admin@example.com","adminEmail":"admin@example.com"}
[DEBUG] Creating session and redirecting {"sessionId":"87654321...","email":"admin@example.com","expires":"2024-02-15T10:30:00.000Z"}
Successful Main Page Load (Admin)
[DEBUG] Incoming request {"method":"GET","path":"/","hasAuth":true,"userAgent":"Mozilla/5.0..."}
[DEBUG] Serving main HTML document
[DEBUG] Checking admin status {"hasCookieHeader":true,"cookieHeader":"session=87654321..."}
[DEBUG] Session ID from cookie {"sessionId":"87654321..."}
[DEBUG] Verifying session {"sessionId":"87654321..."}
[DEBUG] Session data retrieved {"hasData":true,"email":"admin@example.com","expiry":"2024-02-15T10:30:00.000Z"}
[DEBUG] Admin check result {"email":"admin@example.com","adminEmail":"admin@example.com","isAdmin":true}
[DEBUG] User admin status for main page {"isUserAdmin":true}
[DEBUG] Setting Hyperclay admin cookies {"cookies":["currentResource=app; Path=/; Expires=...","isAdminOfCurrentResource=true; Path=/; Expires=..."],"expires":"2024-02-15T10:30:00.000Z"}