Getting Started
Getting Started with Supabase by integrating it to a Next.js application
Last updated
Getting Started with Supabase by integrating it to a Next.js application
Last updated
Supabase can simply be defined as an alternative to Firebase. Diving deeper, Supabase provides core services such as database, authentication, file storage, and autogenerated APIs. It is very useful for frontend developers or mobile developers are you can have a simple functional backend in less than 10 minutes. In this article, we will see how to integrate Supabase into a Next.js application. You can read more about the Next.js project here. However, if you are in hurry feel free to clone and set up the project.
Then create a new branch called supabase
.
The project serves some products but it's actually retrieving the data from a json file. We will use supabase
to fetch the products information. Let's start by retrieving API keys and creating a Product
table in the Supabase dashboard.
Make sure to have an account created at Supabase. When the account is created and verified, you can create a new project.
Then, enter the necessary information to create the project.
After that, you will have access to options on the Dashboard. We need to create a new table and insert data. We will do this directly in the SQL editor.
Here's the SQL script.
Now you will have a ready-to-use Table with data we can fetch.
We’ll need to install the Supabase client package to connect to our Next.js app later. We can do so by running the following command.
After that, create a new file in the project root called supabaseClient.js
.
We are using environment variables so we need to create a .env
file at the root of the project.
To avoid unexpected behaviors, keep the
.env
file and thesupabaseClient.js
in the same directory.
You can find the keys on the project page.
Let's fetch the product list from Supabase now.
In the pages/index.js
file, add an asynchronous function to fetch data from supabase.
The supabase client provides functions and methods to fetch data from a Table in the most intuitive way possible. Remove this line from the imports to avoid conflicts.
Start the dev server and head to http://localhost:3000
.
In this document, we made a quick introduction to Supabase by learning how to set up a project, create a table and fetch data. In the next steps, we will dive into authentication and more complex CRUD operations using Next.js
and Supabase.