StoicBuilder

HandbookII the ForumBrowser storage

IIthe Forum, The shape of an app

Browser storage

1 min readUpdated 28 November

In plain words

Browser storage, such as localStorage and cookies, lets your app keep small bits of data on the visitor's device so they survive a refresh.

Where you see it

In DevTools, open Application, then Local Storage: you may find Quill's dark-mode setting, a half-written draft, or a Supabase sign-in entry whose name starts with sb-. It lives in that one browser and nowhere else.

src/lib/draft.tsbrowser
// save the draft on every changelocalStorage.setItem("quill-draft", JSON.stringify(note)); // read it back after a refreshconst saved = localStorage.getItem("quill-draft");const restored = saved ? JSON.parse(saved) : null;
localStorage only holds text, so objects go in with JSON.stringify and come back with JSON.parse.

What goes wrong

  1. Treating localStorage as the database

    Notes saved only in localStorage vanish when Maya switches to her phone or clears her browser. Anything that matters belongs on the server.

  2. Trusting what's stored there

    Anyone at the keyboard, and any script on the page, can read and change localStorage. A stored isAdmin flag should never make someone an admin.

    localStorage.setItem("isAdmin", "true");
  3. Reading it during server rendering

    localStorage exists only in the browser. Next.js code that touches it while rendering on the server fails with "localStorage is not defined".

What to tell your agent

Copy this into Lovable, Bolt, Cursor or any agent
List everything this app keeps in localStorage, sessionStorage or cookies, and why. Move anything important or security-related to the server, and keep browser storage for preferences and drafts.

Quick check

Sign in to earn +10 XP for it

Maya's Quill notes show on her laptop but not on her phone, though she's signed in on both. Why?

Got a prompt that touches browser storage?

Paste it. You get a better prompt first, then the cards that explain it.

Check your own prompt

Free, no sign-up.