Advent With Friends: Building an Advent Calendar Your Friends Fill, and What the Server Never Tells You
I built Advent With Friends, a free advent calendar that your friends fill for you. You make a calendar, share one link, and each friend hides up to three short notes behind the 24 doors. One door opens per day, and you
I built Advent With Friends, a free advent calendar that your friends fill for you. You make a calendar, share one link, and each friend hides up to three short notes behind the 24 doors. One door opens per day, and you can't peek at a note before its day. There is no sign-up on either side.
The idea is simple. The details are not, because the whole product depends on one promise: the owner cannot see a note early. Here are the technical decisions that mattered, in the order they bit me.
1. The note text never leaves the server before its day
My first instinct was to send the whole calendar to the client and hide locked doors in the UI. That is not a secret, it is a CSS class. Anyone with devtools would read tomorrow's note.
So the rule is: the response builder is the only place where note text can leave the server, and it checks the clock itself.
function doorViews({ role, notes, now, tz, season }) {
return range(1, 24).map((door) => {
const open = isDoorOpen(season, door, tz, now);
const view = { door, open, filled: false };
const note = notes.get(door);
if (!note) return view;
view.filled = true;
view.sticker = note.sticker;
if (role === "owner") {
view.from = note.fromName; // who, yes
if (open) view.message = note.message; // what, only on the day
} else if (note.mine) {
view.message = note.message; // a writer can reread their own
}
return view;
});
}
Three details are worth calling out. The owner gets "who filled it" but not "what", which is what makes the wait fun. A friend only ever sees the notes their own browser wrote, never anyone else's. And an owner who accidentally opens their own fill link in the same browser still waits for the door; being the owner does not count as being the writer.
The test I trust most is boring: fill door 5, fetch the owner JSON before the 5th, and assert the note text does not appear anywhere in the response body.
2. Midnight is the owner's midnight
"One door per day" sounds like a cron job. It isn't. A calendar belongs to a person in a time zone, and if that person is in Auckland, December 1 starts a long time before it does in New York. The browser's time zone is saved when the calendar is created and never changes after that.
Then the open check is a pure function of "what is the calendar date in that zone right now":
function isDoorOpen(season, door, tz, now) {
const p = zonedParts(now, tz); // Intl.DateTimeFormat formatToParts
if (p.year !== season) return p.year > season;
return p.month === 12 && p.day >= door;
}
No stored "opened" flags, no scheduler. The door is open when the calendar's own date has reached it. To tell the user when a door will open, I also need the exact instant of local midnight, which Intl does not give you directly. I compute the zone offset at a guess and then correct it once more, because the offset can differ around that guess (daylight saving, or zones like +5:45). The tests cover half-hour and 45-minute zones and southern-hemisphere summer time.
What about a calendar made on December 10?
This one is a product decision rather than a technical one. If someone creates a calendar on the 10th, doors 1 to 10 are already in the past. Locking them until next year makes no sense, and making the friend fill them with fake-late notes is silly. My rule: past doors open the moment they are filled. Because the check above is just "has the date reached this door", that rule fell out for free.
3. Who is the owner, with no login
I did not want accounts. But "anyone with the link can delete the calendar" is not acceptable either, and neither is "anyone with the link can read the notes".
So there are two kinds of link. The share link carries only a 9-character code (an alphabet without 0 o 1 l i, generated by rejection sampling, with a unique index as the backstop). Opening it lets you fill doors. Ownership is a random token created with the calendar and stored in an HttpOnly cookie. The database keeps only its SHA-256 hash, so a database leak does not hand out ownership.
Cookies do not follow you to another phone, so the owner also gets a private "owner link" with the token in the query string. When that page loads, it exchanges the token for a cookie and removes it from the address bar so it does not stay in history or get pasted by accident. That page also skips analytics for that load.
Friends get a smaller version of the same idea: a writer cookie, again stored as a hash, which lets them reread and delete their own notes in that browser. Lose the cookie and you lose that right. I accepted that trade; it keeps the whole thing accountless.
4. Limits without identities
Without accounts you cannot say "three per person", so I approximated a person two ways. A writer token limits each browser to 3 doors per calendar. A salted hash of the client IP (IPv6 grouped by /64) limits one network to 6. The IP cap is deliberately looser than the token cap, otherwise two people on the same home Wi-Fi would block each other. Neither is airtight, and the calendar itself stops at 24 doors, so the worst case of a determined person is bounded.
Notes are 200 characters, counted in characters rather than bytes so one emoji counts as one. They are stored as plain text, stripped of control, zero-width and bidirectional-override characters, and always rendered as text, never as HTML or auto-linked URLs. A stranger can write into your calendar, so that boundary is not optional.
Everything is deleted on February 1 by an hourly cleanup job, and the FAQ and privacy page say so.
What I would do differently
The part I'd defend hardest is the first one: decide early what the server is allowed to say, and make one function the only exit for private text. The late-start rule also shaped the data model, so it is worth deciding before you build the UI. If you have built something similar, I'd like to hear how you handled time zones for per-person schedules; mine works but I'm not sure it's the cleverest version.
If you want to see how it plays, the free online advent calendar is live now.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.