This guide will help you debug authentication and cookie issues with your Hyperclay-compatible self-updating page.
Set the DEBUG
environment variable to true
in your Val.town settings:
DEBUG=true
This will enable detailed server-side logging for all authentication flows.
Verify these are set correctly:
ADMIN_EMAIL=your-actual-email@domain.com
DEBUG=true
APP_NAMESPACE=default (optional)
- Check that
ADMIN_EMAIL
is set to your exact email address - Enable
DEBUG=true
- Save your val to apply the changes
- 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
- 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
- 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
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
- Look for
- 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)
- 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"
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
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
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
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
- Open DevTools (F12)
- Go to Application → Cookies → [your-domain]
- Look for:
session
(HttpOnly - won't show value)isAdminOfCurrentResource=true
currentResource=app
- 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"}
- Open DevTools → Console
- Look for JavaScript errors
- Check if Hyperclay.js loaded successfully
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
Use browser DevTools to:
- Delete all cookies
- Re-authenticate
- Verify cookies are set correctly
- Test edit functionality
[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"}
[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"}
[DEBUG] Auth email submission {"userEmail":"wrong@example.com","adminEmail":"admin@example.com"}
[DEBUG] Invalid email for auth {"userEmail":"wrong@example.com","adminEmail":"admin@example.com"}
If you suspect storage issues, you can manually check what's stored:
- Look for keys like
default_session_*
anddefault_auth_token_*
- Check expiry timestamps in stored data
- Verify session data contains correct email
Try authentication in:
- Incognito/private mode
- Different browsers
- Different devices
This helps identify browser-specific cookie issues.
If you're still having issues after following this guide:
- Share debug logs: Copy relevant debug log entries
- Describe the exact steps: What you did and what happened
- Check environment: Verify all environment variables are set correctly
- Browser details: Include browser type and version
- Network info: Any proxy, VPN, or network restrictions
The debug logs will show exactly where the authentication flow is failing, making it much easier to identify and fix the issue.