Skip to content

Latest commit

 

History

History
64 lines (50 loc) · 4.97 KB

File metadata and controls

64 lines (50 loc) · 4.97 KB

🏡 Home

Start a new Supabase project Create a Next.js app with the create-next-app CLI Query Supabase data from Next.js Server Components Create an OAuth app with GitHub Authenticate users with GitHub OAuth using Supabase and Next.js Client Components Refresh session cookie for Next.js Server Components with Middleware Restrict access to authenticated users with RLS policies Dynamically render UI based on user session with SSR in Next.js Client Components Implement Protected Routes for authenticated users with Supabase Auth Generate TypeScript definitions from PostgreSQL schema with Supabase CLI Setup a Foreign Key relationship between PostgreSQL tables Automatically generate a profile for every user with PostgreSQL Function Triggers Run authenticated Server-side mutations with Next.js Server Actions Create a PostgreSQL join table in Supabase Studio Implement dynamic buttons with Next.js Client Components Declare global union types with Typescript Implement Optimistic UI with the Next.js useTransition hook Dynamically update UI with Database changes using Supabase Realtime Style a Twitter clone with Tailwind CSS Deploy Next.js App Router project to production with Vercel

Dynamically update UI with Database changes using Supabase Realtime

📹 Video

Supabase allows us to subscribe to changes in the database, and update our UI, without the user needing to refresh the page. In this lesson, we create a subscription for postgres_changes, listening for any change events - insert, update or delete - on our tweets table.

Additionally, we call the router.refresh() function to re-run our Server Components, fetching fresh data from Supabase.

Code Snippets

Subscribe to database changes

const channel = supabase
  .channel("realtime tweets")
  .on(
    "postgres_changes",
    {
      event: "*",
      schema: "public",
      table: "tweets",
    },
    (payload) => {
      router.refresh();
    }
  )
  .subscribe();

Resources


👉 Next lesson


Enjoying the course? Follow Jon Meyers on Twitter and subscribe to the YouTube channel.