Full stack blog with Supabase and Next.js
This code goes along with the blog post The Complete Guide to Full Stack Development with Supabase and Next.js published here
To get started with this project, follow these steps.
-
Create a new project in the Supabase dashboard
-
Click on SQL in the left menu, and execute the following SQL query:
CREATE TABLE posts (
id bigint generated by default as identity primary key,
user_id uuid references auth.users not null,
user_email text,
title text,
content text,
inserted_at timestamp with time zone default timezone('utc'::text, now()) not null
);
alter table posts enable row level security;
create policy "Individuals can create posts." on posts for
insert with check (auth.uid() = user_id);
create policy "Individuals can update their own posts." on posts for
update using (auth.uid() = user_id);
create policy "Individuals can delete their own posts." on posts for
delete using (auth.uid() = user_id);
create policy "Posts are public." on posts for
select using ( true );
Run either locally or deploy to Vercel
Deploying to Vercel
Running locally
- Clone this project
git clone https://github.com/dabit3/supabase-next.js.git
- Change into the directory and install the dependencies
cd supabase-next
npm install
- Create a file named .env.local and update it with the values from your Supabase project:
NEXT_PUBLIC_SUPABASE_URL=https://app-id.supabase.co
NEXT_PUBLIC_SUPABASE_ANON_KEY=your-public-api-key
- Run the server
npm run dev