Expo + Supabase Offline-First Sync

    1

    Builds offline-first sync for Expo apps on Supabase: SQLite outbox, server_seq pull cursor, last-write-wins conflicts, soft deletes, and the locking that stops rows being silently skipped.

    Free

    Security scanned

    Works with the AI Agents you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIDeepSeekDeepSeekMuseMuse+22 more

    Expo + Supabase Offline-First Sync

    Example session with this skill installed

    I need to set up the SQLite outbox table and a write function that ensures the outbox is updated whenever I save a new 'task' to my local Expo database.

    • Read your context and instructions
    • Compiled the expo + supabase

    I have defined the SQLite schema for your outbox and implemented the transactional write pattern. This ensures that every task saved locally is queued for sync without risking data inconsistency.

    SQLite Outbox Implementation

    -- Run this in your local SQLite migration
    CREATE TABLE outbox (
      id INTEGER PRIMARY KEY AUTOINCREMENT,
      tableName TEXT NOT NULL,
      rowId TEXT NOT NULL,
      op TEXT NOT NULL,
      payload TEXT NOT NULL,
      createdAt INTEGER NOT NULL,
      attempts INTEGER DEFAULT 0
    );
    
    CREATE TABLE sync_state (
      tableName TEXT PRIMARY KEY,
      lastSeq INTEGER DEFAULT 0
    );
    
    // Local write module for Expo/Drizzle
    function upsertTask(db, taskValues) {
      const updatedAt = new Date().toISOString();
      
      const result = db.transaction((tx) => {
        // 1. Update the local data table
        tx.insert(tasks)
          .values({ ...taskValues, updatedAt, deletedAt: null })
          .onConflictDoUpdate({ 
            target: tasks.id, 
            set: { ...taskValues, updatedAt, deletedAt: null } 
          }).run();
    
        const saved = tx.select().from(tasks).where(eq(tasks.id, taskValues.id)).get();
    
        // 2. Queue the change in the outbox
        tx.insert(outbox).values({
          tableName: 'tasks',
          rowId: saved.id,
          op: 'upsert',
          payload: JSON.stringify(saved),
          createdAt: Date.now(),
        }).run();
    
        return saved;
      });
    
      // 3. Trigger the sync engine
      notifyChanged('tasks', 'outbox'); 
      return result;
    }
    

    Next steps

    1. Add the server.sql triggers to your Supabase instance to track sequences.
    2. Initialize the sync_state table with your current table names.
    3. Call syncNow() from your useEffect or network listener to push these changes.

    Connects securely to your tools. The creator never sees your data.

    About this skill

    Teaches your coding agent to build a complete offline-first sync engine for an Expo (React Native + web) app on Supabase, with no extra sync service. The UI reads and writes only local SQLite, and a background engine moves changes to and from Postgres.

    The pattern comes from the sync engine of a real offline-first expense app with shared wallets.

    What's included

    • SKILL.md: the rules, client code patterns, sync triggers, sharing, web setup, known limits and a pre-ship test checklist
    • references/server.sql: a ready-to-adapt Postgres setup with the sequence, trigger, RLS policy, push_changes and pull_changes

    What it covers

    • Local writes: a row upsert and an outbox insert in one SQLite transaction
    • Push: batched, atomic, and safe if the user edits a row while a request is in flight
    • Pull: by server-assigned server_seq, so wrong device clocks don't break it
    • Conflicts: last-write-wins per row, with soft deletes that sync to other devices
    • Shared data: why a pull cursor misses old rows that become newly visible, and how to fix it
    • Web: SQLite-WASM with OPFS, the COOP/COEP headers, and offline loading

    The bug most custom sync engines have

    Sequence values are handed out before commit. One transaction can take seq 10 and commit after another commits seq 11. A pull that sees 11 moves past 10 and never sees that row, so data goes missing silently. The included SQL prevents this with an advisory lock.

    Good fit

    Personal or small-team apps with row-level conflicts and a few thousand rows per user.

    Not a good fit

    • Collaborative editing inside one field: use a CRDT instead
    • Many users writing constantly to one database: the lock is global, so every pull briefly blocks writers. The skill explains this limit.

    Testing

    The server SQL passed 20 checks on a throwaway Postgres with a stubbed Supabase auth schema, covering conflicts, row-level security, rollback and the pull/write race. The client snippets are patterns to adapt, not a drop-in library.

    Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for Mobile Development.

    Last-write-wins uses device clocks and works per row, so two devices editing different fields of a row still lose one edit
    The sync lock is global, so every pull briefly blocks writers; not meant for many users writing constantly to one database
    Client code is patterns to adapt, not a drop-in library, and the server SQL assumes Supabase

    How to use

    1. 1

      Connect your agent to the Agensi MCP

      Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup

    2. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 3

      Ask for what you need

      Your agent loads this skill and uses it on your task. It always asks before buying a skill.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill goes through the trust checks below.

    Security scanned

    Checked by our 8-point scan before listing

    Fresh listing

    Recently published to Agensi

    Free to use

    No account required to browse

    Trust & safety

    Security scan

    Security scan passed 13 days ago

    • Free with an Agensi account

    Accounts
    Supabase
    Software
    ExpoDocker (for local Supabase testing)Node.js

    Permissions

    Terminal / Shell
    Read Files
    Write Files
    Listed13 days ago

    What's inside

    Frequently Asked Questions

    No. The engine runs on Supabase Postgres functions and your app's own local SQLite database, with no extra service to pay for or host.

    New in Mobile Development

    Free