Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Supabase 11 min read How-to mediumAdept

Fetching and caching Supabase data in Next.js 13 Server Components

Next.js 13's app directory lets async Server Components query Supabase directly, with caching controlled by an exported `revalidate` value instead of separate getStaticProps/getServerSideProps functions. The walkthrough covers four strategies: static generation with `generateStaticParams`, incremental revalidation (e.g. `revalidate = 60`), fully dynamic fetching (`revalidate = 0`), and client components using `use client`. It closes with a hybrid pattern that loads initial data in a Server Component and passes it to a Client Component subscribed to Supabase Realtime Postgres changes, which separates data fetching from caching policy.

Related posts

  • Using React Query with Next.js App Router and Supabase Cache Helpers

    Supabase mediumAdept

    React Query can be paired with supabase-js in a Next.js App Router app by wrapping the root layout in a client-side QueryClientProvider and creating typed browser and server Supabase clients via @supabase/ssr. Supabase Cache Helpers generate query keys automatically from supabase-js queries, so one reusable query function can be prefetched in a server component and hydrated through HydrationBoundary, letting the client render without a loading state, or fetched purely client-side. The recommendation is to reach for React Query with Server Components only when migrating an existing React Query app or when it covers needs the framework doesn't; otherwise start with the framework's own data fetching.

  • Supabase is now compatible with Next.js 14

    Supabase mediumAdept

    Supabase works across every Next.js 14 rendering context, including App Router Client and Server Components, Route Handlers, Server Actions and Middleware, plus the Pages Router data-fetching functions. Now that Server Actions are stable, auth and mutations can run entirely server-side next to the Server Components that fetch data. supabase-js stores sessions in localStorage by default, which doesn't exist on the server, so it has to be configured with cookie-based storage on both server and browser. The new @supabase/ssr package and a create-next-app starter template (`-e with-supabase`) wrap that boilerplate.

  • supabase-js v2

    Supabase mediumAdept

    supabase-js v2 brings incremental quality-of-life changes over v1. Types are now generated from the database via the CLI and set once on the client. signIn() is split into signInWithPassword() and signInWithOtp(), server-side auth moves to auth.admin, and the auth library is now async to fix a multi-tab token refresh race condition that logged users out. insert/update/upsert no longer return data unless select() is appended, which avoids surprise failures under Row Level Security. Constructor config is scoped per sub-library, each sub-library gets typed errors, Edge Function invocations auto-detect content type, and a new channel() API replaces from().on() for realtime and Postgres change subscriptions. v1 gets security and maintenance patches for three months.

  • Cal.com launches Expert Marketplace built with Next.js and Supabase.

    Supabase mediumAdept

    Cal.com's open-source Platform Starter Kit for building expert marketplaces runs on Next.js and Supabase, having switched from SQLite to Postgres via Prisma shortly before launch once file storage was needed. Prisma connects through Supavisor using a pooled transaction-mode URL plus a direct session-mode URL, and its multiSchema feature keeps app tables out of the PostgREST-exposed public schema. Profile images upload to Supabase Storage via server-generated signed upload URLs, which works alongside Auth.js rather than Supabase Auth, and a custom Next.js Image loader serves resized images. A Vercel integration syncs environment variables and can provision a project with migrations and seeds in one click.

  • Making a Real-Time Chat App with Supabase on Replit

    Replit mediumAdept

    A real-time public chat app can be built with a Vue 3 and Tailwind CSS frontend on Replit backed by Supabase's hosted Postgres. The walkthrough creates a messages table via SQL, enables replication-based real-time events, and wraps the supabase-js client in a Vue composable. That composable handles paginated message loading by range, INSERT subscriptions for live updates, and inserts for sending. Users are identified only by a random username stored in localStorage, and older messages load when the list is scrolled to the top.

The quest for software engineering knowledge.

Look:
Layout: