Flip a flag or fake a permission in your own browser, through one guarded store, with no deploy and no reload.

The problem

Sometimes you just want to see the page as a read-only user, or with a flag turned on, without shipping anything. The usual answer is a one-off localStorage hack in each place that checks a flag. Each one parses its own key, none of them update the page until you reload, and one of them eventually works in production too.

What I concluded

One generic store, created once per domain: flag overrides, permission overrides, locale settings. A guard decides whether writes are allowed in this build, saving to localStorage is opt-in, and React subscribes to it so an override shows up immediately.

const permOverrides = createToggleStore<boolean>({
  guard: () => isDev,             // writes do nothing in prod
  storageKey: "app:perm-overrides",
});

function canEdit(userId: string) {
  const ov = permOverrides.get(`edit:${userId}`);
  if (ov !== undefined) return ov;   // the override wins
  return evaluateRealPermission(userId);
}

Reactive without a reload

The store keeps a version number that goes up on every change, and React reads it through useSyncExternalStore. A hook that checks a permission includes the version in its dependencies, so setting an override re-renders every place that cares.

The version is the snapshot, not the number of entries. Changing an existing value doesn’t change the count, so React would skip the re-render.

The guard runs on load too

Hydrating from localStorage happens before the first render, and the guard applies there as well. A stale entry left in a browser can’t sneak into a production build.

Rules

  • One store per domain. Don’t mix permission overrides with flag overrides.
  • Always pass a guard. Without one, production users can write overrides too.
  • The override always wins. Every evaluator checks it first.
  • It’s a convenience, not a security boundary. Anyone can change client code, so the server still enforces every real permission. A faked “can edit” only changes what the UI shows.

What you get

Testing a state is one call in the console, and the page updates as you make it. All the hacks collapse into one small store with one set of rules.

Related: Access control, Layers.