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.
// 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.
| File | What it does |
|---|---|
config.ts | Tenant, region, CDN, and getApiSecret() |
demo-credentials.ts | The one hardcoded credential, and why yours does not go there |
sso.ts | Builds the signed payload. Server-only |
index.tsx | Routes, the login state, and the widget |
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.
- Get a tenant ID and API secret from your account. Free 30 day trial, then plans from $0.99/mo.
- Add FASTCOMMENTS_TENANT_ID here: https://www.val.town/x/fastcomments/sso-demo/environment-variables?key=FASTCOMMENTS_TENANT_ID
- Add FASTCOMMENTS_API_SECRET here: https://www.val.town/x/fastcomments/sso-demo/environment-variables?key=FASTCOMMENTS_API_SECRET
- Add your val's domain to the account's allowed domains.
EU accounts also set FASTCOMMENTS_REGION to eu.
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.
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.