Public
Log in with Val Town, land logged into the comments
commentsfastcommentsoauthsso
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.

Log in with Val Town, comment as yourself

A FastComments thread where you are already signed in. No second login, no comment-specific account, no password.

Live: https://fastcomments-sso.val.run

Your val already knows who the visitor is. Secure SSO hands that identity to the comment widget: serialize the user, sign it with HMAC-SHA256, pass three values to the widget. There is no endpoint to call and nothing to await.

Here the identity comes from std/oauth, so the visitor logs in with the Val Town account they already have. Swap that for whatever your app uses; the FastComments half does not change.

The whole thing

// sso.ts, on the server const payload = new SecureSSOPayloadBuilder(getApiSecret(), { id, email, username, displayName, avatar, }).getPayload(); // index.tsx, into the widget config sso: { ...payload, logoutURL: "/logout" }

payload is { userDataJSONBase64, verificationHash, timestamp }. The secret signs it and is then dropped. Nothing in the page lets a reader forge a different user.

Files

FileWhat it does
config.tsTenant, region, CDN, and getApiSecret()
demo-credentials.tsThe one hardcoded credential, and why yours does not go there
sso.tsBuilds the signed payload. Server-only
index.tsxRoutes, the login state, and the widget

Where the secret lives

Read demo-credentials.ts before copying anything here.

This val ships working because it falls back to the API secret for FastComments' public demo tenant, which is published in FastComments' own examples and only works against that shared sandbox. That is the exception, not the pattern. getApiSecret() reads FASTCOMMENTS_API_SECRET from the environment first, and that is the path your deployment takes.

Two Val Town specifics make this sharper than usual:

  • A val's source is public. Anything in a file is readable by anyone who opens the val.
  • Remixing copies env var keys but not values, so a secret in an env var does not follow your val into someone else's account. A secret in a file does.

If you point FASTCOMMENTS_TENANT_ID at your own tenant and forget the secret, the val throws with an explanation, rather than signing with the demo key and failing every request with "SSO payload hash error", which reads like a bug in your own code.

Make it yours

  1. Get a tenant ID and API secret from your account. Free 30 day trial, then plans from $0.99/mo.
  2. Add FASTCOMMENTS_TENANT_ID here: https://www.val.town/x/fastcomments/sso-demo/environment-variables?key=FASTCOMMENTS_TENANT_ID
  3. Add FASTCOMMENTS_API_SECRET here: https://www.val.town/x/fastcomments/sso-demo/environment-variables?key=FASTCOMMENTS_API_SECRET
  4. Add your val's domain to the account's allowed domains.

EU accounts also set FASTCOMMENTS_REGION to eu.

Notes

isAdmin and isModerator are never set from the session. Signing in with a Val Town account says nothing about who should moderate your site; grant those from your own roles.

The SSO user id is namespaced vt-<val town user id> and must stay stable, or the same person gets a new comment identity on every login.

Val Town does not always expose an email, and FastComments requires a unique one, so the fallback derives it from the stable id rather than sharing one placeholder across users.

More

val.town/x/fastcomments/skills is a remixable library of FastComments agent skills, including one on SSO covering group-gated threads, badges, SAML, and the usual hash failures. Townie and the Val Town MCP server pick them up once the remix is in your account.

val.town/x/fastcomments/blog-with-comments is the simpler starting point: a blog with anonymous comments and no key at all.