Database

Why Supabase?

ZapStart comes preconfigured with Supabase as the default database. We chose Supabase because it’s a free, open-source alternative to Firebase that is easy to set up, simple to use, and comes with excellent documentation. It offers a scalable solution for handling authentication, real-time data, and database queries without the need for complex configurations.

Get started with Supabase

To get started, create an account on the Supabase website. Once logged in, follow these steps to create your project:

  1. Click on Create New Project and fill in the necessary details.
  2. Navigate to the Database section to create a new table.
  3. Go to the API section to find your API keys and project URL.

Add your Supabase keys to your project

After setting up your Supabase project, update the environment variables in the .env.local file in your project with your own keys:

.env.local
NEXT_PUBLIC_SUPABASE_URL=your-supabase-url
NEXT_PUBLIC_SUPABASE_ANON_KEY=your-anon-key
NEXT_PUBLIC_SUPABASE_SECRET_KEY=your-secret-key

Using Supabase in your project

ZapStart provides a pre-built client file, supabaseAdmin.ts, which creates a Supabase client for interacting with your database. You can use this client to run database queries and interact with Supabase services like authentication, real-time features, and more.

Here’s an example of how to use the supabaseAdmin client to fetch data from your database:

supabaseAdmin.ts
import { createClient } from "@supabase/supabase-js"

const supabaseAdmin = createClient(
  process.env.NEXT_PUBLIC_SUPABASE_URL as string,
  process.env.NEXT_PUBLIC_SUPABASE_SECRET_KEY as string
)

export { supabaseAdmin }

// Example usage to fetch data
const { data, error } = await supabaseAdmin
  .from("users")
  .select("*")

Some useful tables to create

Supabase makes it easy to work with any type of data. Some useful tables you might want to create include:

  • Users: To store user information for authentication or user profiles.
  • BlogPosts: To store blog content, including titles, content, and metadata.
  • Comments: For managing comments on blog posts or other user-generated content.

Alternative database solutions

While Supabase is the default option in ZapStart, you can integrate any database solution of your choice. However, doing so may require adjusting parts of the code to work with the new database API or driver.