--- title: 'Use Supabase with Next.js' subtitle: 'Learn how to create a Supabase project, add some sample data, and query from a Next.js app.' breadcrumb: 'Framework Quickstarts' hideToc: true --- Go to [database.new](https://database.new) and create a new Supabase project. When your project is up and running, go to the [Table Editor](https://supabase.com/dashboard/project/_/editor), create a new table and insert some data. Alternatively, you can run the following snippet in your project's [SQL Editor](https://supabase.com/dashboard/project/_/sql/new). This will create a `notes` table with some sample data. ```sql SQL_EDITOR -- Create the table create table notes ( id bigint primary key generated always as identity, title text not null ); -- Insert some sample data into the table insert into notes (title) values ('Today I created a Supabase project.'), ('I added some data and queried it from Next.js.'), ('It was awesome!'); alter table notes enable row level security; ``` Make the data in your table publicly readable by adding an RLS policy: ```sql SQL_EDITOR create policy "public can read notes" on public.notes for select to anon using (true); ``` Use the `create-next-app` command and the `with-supabase` template, to create a Next.js app pre-configured with: - [Cookie-based Auth](https://supabase.com/docs/guides/auth/auth-helpers/nextjs) - [TypeScript](https://www.typescriptlang.org/) - [Tailwind CSS](https://tailwindcss.com/) ```bash Terminal npx create-next-app -e with-supabase ``` Rename `.env.example` to `.env.local` and populate with your Supabase connection variables: ```text .env.local NEXT_PUBLIC_SUPABASE_URL= NEXT_PUBLIC_SUPABASE_ANON_KEY= ``` Create a new file at `app/notes/page.tsx` and populate with the following. This will select all the rows from the `notes` table in Supabase and render them on the page. ```ts app/notes/page.tsx import { createClient } from '@/utils/supabase/server'; export default async function Notes() { const supabase = await createClient(); const { data: notes } = await supabase.from("notes").select(); return
{JSON.stringify(notes, null, 2)}
} ``` ```ts utils/supabase/server.ts import { createServerClient } from '@supabase/ssr' import { cookies } from 'next/headers' export async function createClient() { const cookieStore = await cookies() return createServerClient( process.env.NEXT_PUBLIC_SUPABASE_URL!, process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!, { cookies: { getAll() { return cookieStore.getAll() }, setAll(cookiesToSet) { try { cookiesToSet.forEach(({ name, value, options }) => cookieStore.set(name, value, options) ) } catch { // The `setAll` method was called from a Server Component. // This can be ignored if you have middleware refreshing // user sessions. } }, }, } ) } ```
Run the development server, go to http://localhost:3000/notes in a browser and you should see the list of notes. ```bash Terminal npm run dev ```
## Next steps - Set up [Auth](/docs/guides/auth) for your app - [Insert more data](/docs/guides/database/import-data) into your database - Upload and serve static files using [Storage](/docs/guides/storage)