import { TutorialStep } from "./tutorial-step"; import { CodeBlock } from "./code-block"; const create = `create table notes ( id bigserial primary key, title text ); insert into notes(title) values ('Today I created a Supabase project.'), ('I added some data and queried it from Next.js.'), ('It was awesome!'); `.trim(); const rls = `alter table notes enable row level security; create policy "Allow public read access" on notes for select using (true);`.trim(); const server = `import { createClient } from '@/lib/supabase/server' export default async function Page() { const supabase = await createClient() const { data: notes } = await supabase.from('notes').select() return
{JSON.stringify(notes, null, 2)}
}
`.trim();
const client = `'use client'
import { createClient } from '@/lib/supabase/client'
import { useEffect, useState } from 'react'
export default function Page() {
const [notes, setNotes] = useState{JSON.stringify(notes, null, 2)}
}
`.trim();
export function FetchDataSteps() {
return (
Head over to the{" "} Table Editor {" "} for your Supabase project to create a table and insert some example data. If you're stuck for creativity, you can copy and paste the following into the{" "} SQL Editor {" "} and click RUN!
Supabase enables Row Level Security (RLS) by default. To query data
from your notes table, you need to add a policy. You can
do this in the{" "}
Table Editor
{" "}
or via the{" "}
SQL Editor
.
For example, you can run the following SQL to allow public read access:
You can learn more about RLS in the{" "} Supabase docs .
To create a Supabase client and query data from an Async Server Component, create a new page.tsx file at{" "} /app/notes/page.tsx {" "} and add the following.
Alternatively, you can use a Client Component.
Head over to the{" "} Supabase UI library {" "} and try installing some blocks. For example, you can install a Realtime Chat block by running:
You're ready to launch your product to the world! 🚀