This guide will walk you through the process of connecting your Next.js 14 SaaS application to Supabase using Prisma ORM. You'll learn how to set up a new project in Supabase, retrieve the necessary connection string, and configure it in your application.
- Visit the Supabase website and sign in to your account or sign up if you don't have an account yet.
- Once logged in, navigate to the Supabase dashboard and click on "New Project". Fill out the project details including project name, database password, and region. Click "Create New Project" and wait for your project to be initialized. This can take a few minutes.
- Once your project is ready, select it from the Supabase dashboard. Go to the "Settings" tab and then click on "Database".
- In the "Database" settings, look for the "Connection Info" section. Copy the connection string provided there. It usually starts with postgres://.
With your connection string in hand, edit the following .env line.
1
DATABASE_URL="paste the connection string here"
Run the following line in your terminal to generate prisma schema. Please make sure to run this while your Nextjs application is off.
1
npx prisma generate
After setting up your Prisma schema and generating the Prisma client, run the following command in your project's root directory:
1
npx prisma db push