Dev.to WebDev 🛠 Dev 👁 2 📖 5 min read

Engineering a product with no accounts: how I built Fill My Advent Calendar

Fill My Advent Calendar is an online advent calendar with 24 doors that your friends fill for you. You share a link, your friends each seal a note behind a door, and you open one door a day from December 1 to December 24

Engineering a product with no accounts: how I built Fill My Advent Calendar

Fill My Advent Calendar is an online advent calendar with 24 doors that your friends fill for you. You share a link, your friends each seal a note behind a door, and you open one door a day from December 1 to December 24. It runs in your phone or computer browser, and nobody needs an app or an account to use it.

One constraint shaped everything: a friend arrives from a group chat link and writes a note, and there's no sign-up for anyone. That one rule creates four problems:

  • Who owns a calendar if there's no user database.
  • How a friend finds their way back to the calendar without a saved account.
  • How the server keeps notes secret until their specific day.
  • How to define "today" for an owner living in a different time zone than the server.

No accounts: a token in a cookie, a hash in the database

The stack is a Next.js app with a PostgreSQL database. There's no user table involved in making, filling or opening a calendar.

When you make a calendar, the server makes an owner token. This is a sequence of 24 random bytes, base64url encoded. The server puts this token into an httpOnly cookie in your browser.

The database stores only the SHA-256 hash of that token. Owning a calendar means holding the cookie whose hash matches the one in my database.

Friends get one random browser key in the same way, also in an httpOnly cookie, also stored only as a SHA-256 hash.

That key is what caps a friend at 3 doors per calendar, so 24 doors need at least 8 friends. It's also the friend's snowflake wallet. Snowflakes are the site's own points for optional extras.

Link previews, crawlers and scripts never get a key: only a real page navigation from a browser does. So a link unfurled in WhatsApp or Slack doesn't create a wallet.

Codes a person can type back from a story

The calendar id is the 8-character code itself. The alphabet has 30 characters. It leaves out 0, O, 1, I, L and U, so a code read off an Instagram story can be typed back without guessing.

That gives 30^8 = 656,100,000,000 possible codes (about 656 billion).

alphabet   23456789ABCDEFGHJKMNPQRSTVWXYZ   (30 characters)
length     8
codes      30^8 = 656,100,000,000
shown as   5D39-S5CY

The code is shown as two groups of four. "5D39S5CY" is shown as "5D39-S5CY".

The code field accepts lower case letters, spaces, dashes, or a whole pasted link, and turns them all into the same id. A friend who only saw the code types it at the code page.

A new advent calendar with 24 empty doors, the share buttons and the 8-character calendar code H2QZ-HSCF.

Sealed means the server never sends the note early

The sealed part is enforced on the server, not hidden in the page. When a friend views the calendar, the database query returns only three fields: the door number, the "from" name and the stamp. The content of the note isn't in that response at all.

When you try to view a note, the route first checks the current open-door count. If the door number is higher than that count, it answers "not yet". The route never loads the note, so there's nothing in the response to find.

The Christmas Eve song is made only when the open-door count reaches 24, so the server reads the notes for the lyrics no earlier than the owner can.

A friend's view of Mia's advent calendar: taken doors show an envelope, door 3 is picked, and the note form says Mia opens it on December 3.

"Today" is the owner's day, not the server's

I store the owner's IANA time zone (for example "Europe/Berlin") when the calendar is made. I work out "today" from it using Intl.DateTimeFormat with formatToParts. I don't use any date library.

The whole unlock rule is one small function. Before December of the calendar's year, it returns 0 doors. During December, it returns the day of the month, capped at 24. After that year, it returns all 24.

/** How many doors are open today (0-24). Door n opens at local midnight on December n. */
export function openDoorCount(year: number, timeZone: string, now: Date = new Date()): number {
  const today = localDate(timeZone, now); // { year, month, day } via Intl.DateTimeFormat
  if (today.year > year) return 24;
  if (today.year < year || today.month < 12) return 0;
  return Math.min(24, today.day);
}

This rule is also why a calendar made on December 3 works. Doors 1, 2 and 3 are already open, so a note sealed behind door 2 can be read at once.

Two friends, one door

I use a unique index in the database to prevent two friends from claiming the same door. When a friend saves a note, the insert operation runs with "on conflict do nothing". If a second friend tries to take the same door, the database returns a "taken" result instead of overwriting the previous entry.

The first time the owner reads a note, the server stamps an "opened at" time on it with a conditional update, only where it was still empty. So the 1 snowflake for opening a door is paid once, even if two requests arrive together.

What stays free

Making, sharing, filling and opening are free with no card. You can add written notes, photos, voice messages and song links without paying. Plain wrapping and the "None" opening effect are also free. Every extra and its cost is on the price list.

A checklist if you build something with no accounts

If you're planning to build a project that avoids traditional sign-up flows, apply these four checks:

  1. Store hashes, not tokens: Use SHA-256 hashes in your database to identify users while keeping their browser tokens private.
  2. Never trust the page to hide data: Keep the sensitive content on the server and send it only when the server's own rule says it's time.
  3. Pick the user's time zone on purpose: Store the user's IANA time zone when the thing is made, and work out "today" from it.
  4. Let the database settle races: Use unique indexes and "on conflict" clauses to handle two requests that arrive together without corrupting state.

Disclosure: I built Fill My Advent Calendar. Everything above describes its own code as it runs today.

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.