Ahmed Benlafqih

All projects

Quest Log, an offline-first gamified to-do app with per-user data isolation

Personal project · 2026

Personal gamified to-do PWA in plain JavaScript: offline-first, Supabase sync, owner-only row-level security in its setup script. Built alone with an AI agent.

Source code

In short

What it is
A gamified to-do list as a progressive web app in plain HTML, CSS and JavaScript. It works offline, writing to the browser first and syncing to a Supabase database, where the repository's setup script limits each account to its own rows.
Why
A personal tool to beat procrastination (a daily "boss quest" is the task you keep dodging), in use by me and a few friends, each with their own account.
My role
Personal project, built alone with the help of an AI coding agent.
Domains and tech
Cloud security. Plain JavaScript (no framework or build step), service worker, Supabase (Postgres, auth, row-level security), Cloudflare Pages.
Status
Personal project: in personal use; written with an AI coding agent; no tests, CI or CSP. In use. A small personal tool with a working offline-first sync; no tests, no CI, and no Content-Security-Policy.
Period
2026

Context and problem

Quest Log is a gamified to-do list I built for myself and use, along with a few friends who each have their own account. It turns the task you keep avoiding into a daily “boss quest” worth triple XP. It’s a personal project, built alone with the help of an AI coding agent. Public sign-up is closed and the app has no sign-up screen; if you’d like an account to try it, email me and I’ll set one up.

I’m showing it for one reason that fits a security portfolio: it’s the one project here that relies on per-user data isolation on a managed cloud database. The rest of this page is about how that works and where its limits are.

Role, use and AI assistance: stated by me. Everything else: read from the code.

Architecture

Quest Log: offline-first sync and the access boundaryThe browser writes every change to localStorage first and marks it dirty. A sync pushes dirty records to Supabase and pulls rows changed since a cursor; the last device to sync wins. Requests carry the user's session and the publishable key only. In Postgres, row-level security allows each signed-in user to read and write only rows whose user_id equals their own id.Browser (PWA, plain JavaScript)· writes to localStorage first, marks records dirty· service worker caches the app shell for offline useSync· push: upsert dirty records (chunks of 200)· pull: rows changed since the cursor (10 s overlap)· conflicts: last device to sync winsSupabase Auth: email + password sign-inthe client holds only the publishable keyPostgres: tasks, sessionsrow-level security, one policy per table:user_id = auth.uid() for read and write
Offline-first flow and the access boundary. The browser writes locally first and syncs in the background; in the database, row-level security (the highlighted box) is what keeps one account's data out of another's.Read from app.js, sw.js and supabase-setup.sql

The app is plain HTML, CSS and JavaScript with no framework and no build step. Every change is written to the browser’s localStorage first and marked “dirty”, so the app works offline; a service worker caches the app shell. A background sync pushes dirty records to a Supabase Postgres database and pulls back rows changed since a saved cursor. Conflicts are resolved last-write-wins, which the README states plainly as “not built for heavy collaboration”.

Data isolation

This is the part worth looking at. Authentication is Supabase email-and-password sign-in from the browser, and the page only ever holds Supabase’s publishable key, the kind meant to ship in a browser, never a secret key. On its own that key would let anyone read the tables, so the real boundary is in the database.

The app syncs exactly two tables, and the repository’s setup script enables row-level security on both, with one policy each that ties every read and write to the signed-in user:

supabase-setup.sql

create policy "tasks: own rows" on public.tasks
  for all to authenticated
  using (user_id = auth.uid())
  with check (user_id = auth.uid());

auth.uid() is the id of the account making the request, so under the setup script’s policies a user can only ever touch rows that are already theirs, and unauthenticated requests get nothing. A server-side trigger stamps updated_at on every write, which is what the sync cursor relies on.

Limitations

I’d rather state these than hide them:

  • No Content-Security-Policy. The UI builds HTML by string concatenation, with an escaping helper on user text as the only guard against injection. A CSP is the obvious next addition.
  • XP is computed on the client. The server stores the value the browser sends, so a signed-in user could write any XP to their own rows. The damage stops at their own data, if the live database matches the setup script.
  • Data stays on the device after logout. Logout signs out locally and forgets the account, but the cached tasks remain in localStorage, and the app reopens the last profile offline without re-authenticating.
  • The live database wasn’t checked. This page describes the setup script in the repository; I haven’t verified that the live Supabase project has the same settings.
  • No tests and no CI. The game logic is written so it could be imported and tested from Node, but no tests are committed.

Possible next steps

Add a Content-Security-Policy and the other standard headers, move XP validation server-side, and clear cached data on logout. The row-level security is the piece I’d keep as is.