Two links and no accounts: how a shared advent calendar handles ownership
This December I built a small side project: an online advent calendar that friends fill together. One person creates it, shares a link in the group chat, and each friend hides a note, photo, song or voice message behind one of 24 doors. The owner opens one door a day until Christmas Eve.
The product rule I cared most about was "no sign-up". Nobody wants to create an account to leave a two-line note for a friend, and the owner shouldn't need one either. So the whole permission model is two links. Here's how that works and the small details that made it safe enough.
Two links, two capabilities
When you create a calendar, the server generates two random strings:
const id = randomId(10); // public: goes in the invite link
const ownerKey = randomId(24); // secret: goes in the owner's private link
- The invite link carries only the calendar id. Anyone with it can add a wish to an empty door and see which doors are taken. That's it.
- The private link carries the owner key. It's the only thing that can read wishes, and only for doors that have already unlocked.
The owner key is returned exactly once, in the response to the create request. The database never sees it:
await env.DB.prepare(
"INSERT INTO calendars (id, owner_key_hash, owner, title, year, tz, created_at) VALUES (?, ?, ?, ?, ?, ?, ?)"
).bind(id, await sha256(ownerKey), owner, title, year, tz, Date.now()).run();
return json({ id, ownerKey, owner, title, year, fillUrl: `/fill?c=${id}` }, 201);
Checking ownership later is just hashing whatever key the request brings and comparing:
export async function isOwner(cal, key) {
if (!key || typeof key !== "string") return false;
return (await sha256(key)) === cal.owner_key_hash;
}
A plain SHA-256 is fine here because the key isn't a human password: it's 24 characters from a 32-character alphabet, so about 120 bits of randomness. There's nothing to brute-force from a leaked hash.
An alphabet that survives being read aloud
The ids come from this helper:
const ALPHABET = "abcdefghijkmnpqrstuvwxyz23456789";
export function randomId(length) {
const bytes = crypto.getRandomValues(new Uint8Array(length));
let out = "";
for (const b of bytes) out += ALPHABET[b % 32];
return out;
}
Two deliberate choices:
- No look-alikes.
l,1,oand0are gone, so a link copied off a phone screen or read over a call still works. - Exactly 32 characters. A byte has 256 values and 256 is divisible by 32, so
b % 32is perfectly uniform. With a 36-character alphabet, the first few characters would come up slightly more often.
"Anonymous" means not stored
Friends can sign a wish or leave it anonymous with a clue ("we once missed the last train home"). The tempting implementation is to store the name and hide it in the UI. Instead, the API drops it before it reaches the database:
const anonymous = form.get("anonymous") === "1";
// Anonymous wishes are truly anonymous: no name is stored at all.
const name = anonymous ? "" : cleanText(form.get("name"), 40);
const clue = anonymous ? cleanText(form.get("clue"), 80) : "";
If the owner (or I) ever wanted to find out who wrote door 14, there's nothing to find.
Cleaning up when two friends race for the same door
Door ownership is a composite primary key, PRIMARY KEY (calendar_id, day). The API checks first so it can return a friendly message, but two people can still pass the check at the same moment. The insert is the real guard, and if it loses, any photo or voice note it already uploaded to storage gets removed:
try {
await env.DB.prepare(`INSERT INTO wishes (...) VALUES (...)`).bind(...).run();
} catch (err) {
if (mediaKey) await env.MEDIA.delete(mediaKey);
if (String(err).includes("UNIQUE") || String(err).includes("PRIMARY KEY")) {
return fail(409, "taken", `Door ${day} was just taken. Pick another one!`);
}
throw err;
}
No orphaned files, and the slower friend gets a 409 and picks another door.
What I'd keep for the next project
Capability links aren't right for everything (you can't revoke one without rotating it, and anyone who sees the private link has access). For a seasonal, low-stakes, share-in-a-group-chat product, they remove the single biggest source of friction, and the implementation is a few dozen lines.
The calendar is live at Advent With Friends if you want to see the two-link flow end to end. It's a free online advent calendar you fill with friends, and there's a list of ideas for what to hide behind each door.
All rights reserved