Database
This template uses Supabase as a database and authentication provider. Here's a quick introduction if you've never heard of it.
5-Min Walkthrough
Setup
1. Create a Supabase project
Sign up for a Supabase account and create a new organization and project.
You'll be shown a project ID
and anon key
for the new project. Copy these over to your .env
file.
Next, go to your project page > Settings > API > Project API Keys, and copy the service role key
over to your .env
file. Your environment variables should look like this:
2. Run migrations on your database
The template comes out-of-the-box with a bunch of database migrations – SQL queries that will set up the tables for your database.
Running these migrations will help you get set up for all the other features in the template, including authentication, Stripe payments, and image generation.
To run the migrations, run these three commands in your shell:
Note that the project ref will be the id-like part of the Supabase URL you pasted in Step 1, ignoring the "https://" and ".supabase.co".
That's it! Visit the Supabase Dashboard > Your Project > Tables to ensure the new tables have been added to the database.
The migration files handle two other jobs:
- Adding storage buckets under Your Project > Storage, so you can store files like user avatars and generated images
- Setting up pgvector and vector search functions, so you can store pieces of texts with vector embeddings and perform Retrieval Augmented Generation (RAG). (Think: features like "chatting with PDFs".)
3. Set up authentication
The last thing you'll want to do while on the Supabase dashabord is to configure authentication. Check out the Authentication tutorial to set up Magic Links and Google OAuth with Supabase.
Running Supabase locally
You can run Supabase locally for development to keep your production and development databases separate. Follow the official Supabase Local Development guide to learn more.
If you're running Supabase locally, browse through the supabase/config.toml
file to set up configurations for the local database. To enable Google Auth locally, switch enabled = true
on Line 134 (it is turned off by default). Make sure to set your project_id
correctly as well.
Last Updated: June 7