Skip to content

Latest commit

 

History

History
80 lines (58 loc) · 5.56 KB

File metadata and controls

80 lines (58 loc) · 5.56 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

Run authenticated Server-side mutations with Next.js Server Actions

📹 Video

Server Actions are a way to perform server-side mutations in the Next.js App Router. In this lesson, we create a <NewTweet /> component that renders a form for the user to enter a new tweet. This form is submitted to a Server Action, which writes this data to Supabase.

Additionally, we create a Server Action Supabase client and call the getUser function to fetch the currently signed in user.

Lastly, we write a Row Level Security (RLS) policy to enable the insert action for authenticated users.

Code Snippets

Posting form to Server Action

export default function NewTweet() {
  const addTweet = async () => {
    "use server";
  };

  return <form action={addTweet}>...</form>;
}

Create Supabase client in Server Action

const supabase = createServerActionClient<Database>({ cookies });

Get user from Supabase client

const {
  data: { user },
} = await supabase.auth.getUser();

Insert tweet with Supabase

await supabase.from("tweets").insert({...});

Resources


👉 Next lesson


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