Skip to content

Latest commit

 

History

History
89 lines (67 loc) · 5.52 KB

File metadata and controls

89 lines (67 loc) · 5.52 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

Create a PostgreSQL join table in Supabase Studio

📹 Video

In this lesson, we create a PostgreSQL join table for likes. This has a many-to-many relationship between the profiles and tweets table, allowing us to store each instance of a like between a user and a tweet.

Additionally, we create Row Level Security (RLS) polices to enable select, insert and delete.

Code Snippets

Create likes table

create table public.likes (
  id uuid default gen_random_uuid() primary key,
  created_at timestamp with time zone default timezone('utc'::text, now()) not null,
  user_id uuid references public.profiles on delete cascade not null,
  tweet_id uuid references public.tweets on delete cascade not null
);

Enable Row Level Security

alter table public.likes enable row level security;

Enable insert action with RLS policy

create policy "authenticated users can insert their own likes" ON "public"."likes"
as permissive for select
to authenticated
using (user_id = auth.uid());

Enable delete action with RLS policy

create policy "authenticated users can delete their own likes" ON "public"."likes"
as permissive for delete
to authenticated
using (user_id = auth.uid());

Enable select action with RLS policy

create policy "authenticated users can select likes" ON "public"."likes"
as permissive for select
to authenticated
using (true);

Resources


👉 Next lesson


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