Get your API key

Lesson 5 of 6

Save data properly

Start with browser storage, then move to a Supabase database with security rules on.

9 min Log in to open
One step at a time, like flipping pages.

By the end of this lesson your routines and ticks will survive a refresh: first with browser storage, then in a Supabase database where each user sees only their own data, with security rules ON.

You need: the working screens from lesson 4, a free Supabase account, your coding agent · Time: 8 minutes

  1. Right now your routines live in the page's memory, so a refresh wipes them. The quickest fix is localStorage: a small notebook inside the browser, kept separately for each website.

    What you should know about it:

    • It keeps data after a refresh and after closing the browser.
    • It holds about 5 MB per website, plenty for thousands of routines.
    • It lives on one browser on one device. Your phone and laptop each have their own copy.
    • It is deleted when the user clears browsing data, and private (incognito) windows may not keep it.
    • Anyone using that browser can read it, so never store passwords or private data in it.
    Prompt · copy it into your AI agent
    Read PRD.md first.
    Save all routines and daily ticks in localStorage so they survive a page refresh and closing the browser.
    Rules:
    - Use one localStorage key called "daily-routine-v1".
    - Store each tick by date as YYYY-MM-DD using the LOCAL date of the device, not the UTC date (I am in India, IST, and the day must change at midnight IST, not at 5:30 am).
    - If the saved data is missing or broken, start with an empty list and show the empty state; never crash.
    - Do not change how any screen looks.
    When done, tell me 3 steps to test it, including a refresh test.
    Why?

    localStorage needs no account, no server and no keys, so it is the safest first step. The local-date rule matters in India: many apps use UTC dates by mistake, and then "today" flips at 5:30 in the morning and breaks every streak.

Log in free to read the rest of this lesson

Every lesson is free. A free account unlocks all of them and saves your progress.

Still to come in this lesson:

  1. Test that it really saves
  2. Move to Supabase when you need it
  3. Know your two keys
  4. Turn on RLS with real policies
  5. Check with the Security Advisor and two users
  6. Recap