Supabase Setup
Learn how to set up your application with Supabase as the database and storage provider.
In this guide, we'll show you how to set up your application with Supabase as the database and storage provider.
Note We will use Supabase as the database and storage provider. The authentication feature of Supabase is not used, as we use Better Auth for authentication, which stores user data directly in your database.
Before we start, make sure you have a Supabase account. If you don't have one yet, you can create one for free at supabase.com.
1. Create a new Supabase project
- Go to supabase.com and sign in
- Click New Project
- Fill in your project details:
- Name: Your project name
- Database Password: Choose a strong password (save this!)
- Region: Choose a region close to your deployment (see note below)
Region Selection Make sure your application and database are physically close. If you use Vercel and Supabase, make sure they are in the same AWS region. For example: - Vercel (D.C.) and Supabase (Virginia): Both are in the us-east-1 region, which results in a fast application - Vercel (D.C.) and Supabase (Ohio): You are dealing with two different AWS regions, the app can be up to 3-12x slower!
2. Get connection strings
In the Supabase dashboard, click the Connect button in the top row.
Select the ORM tab and Drizzle as the tool.
You will need the DATABASE_URL. For Drizzle, you can use the connection pooling URL or the direct connection URL.
3. Set environment variables
Open your .env file and set the environment variables as follows:
For Connection Pooling (Recommended)
# Connection pooling URL (recommended for production)
DATABASE_URL="postgres://postgres.[your-supabase-project]:[password]@aws-0-[aws-region].pooler.supabase.com:6543/postgres?pgbouncer=true"For Direct Connection
# Direct connection URL (for migrations and development)
DATABASE_URL="postgresql://postgres:[password]@db.[your-project-ref].supabase.co:5432/postgres"Important Make sure to replace the password and project ref placeholders with your own values from the Supabase dashboard.
4. Run migrations
To push the database schema to Supabase, run the following command:
npm run db:pushOr if you prefer to use migrations:
npm run db:generate
npm run db:migrateDatabase access and RLS The shipped app uses Drizzle on the server. It does not configure the Supabase Data API or map Better Auth sessions or JWT claims into RLS policies. Better Auth does not replace RLS. If you expose the Data API or query Supabase from client code, design and test RLS policies for every exposed table first.
5. Connect Supabase storage for file uploads
To enable the shipped user avatar and organization logo uploads, you can use Supabase Storage through its S3-compatible endpoint.
Create a storage bucket
- Go to the Storage tab in the Supabase dashboard
- Click the Create bucket button
- Name the bucket, for example
avatars - Deactivate the Public bucket switch to prevent direct anonymous object access
- Optionally, define a maximum file size and restrict file types for this bucket
Application access remains public by key
The private bucket setting does not add authorization to the starter kit. The
shipped /storage/[...path] route does not read a session or check
ownership. Anyone who knows an image key can ask the application for a signed
download redirect. Add a protected route and file ownership metadata before
storing private files.
Get storage credentials
- Navigate to Project settings from the sidebar
- Select the Storage tab
- Scroll down to the S3 access keys section
- Click the New access key button
- Enter a description for your access key
- After clicking Create access key, copy the Access key ID and Secret access key
Configure environment variables
Add the following environment variables to your .env file:
S3_ACCESS_KEY_ID="your-access-key"
S3_SECRET_ACCESS_KEY="your-secret-key"
S3_ENDPOINT="https://[YOUR-PROJECT-REF].storage.supabase.co/storage/v1/s3"
S3_REGION="[YOUR-PROJECT-REGION]"
NEXT_PUBLIC_IMAGES_BUCKET_NAME="avatars"Copy the endpoint and region shown with the S3 access keys in the Supabase dashboard. The region participates in request signing, so do not substitute a region from another project.
6. Confirm storage configuration
No storage code change is required for the bucket name. The shipped configuration reads NEXT_PUBLIC_IMAGES_BUCKET_NAME:
import { env } from '@/lib/env';
export const storageConfig = {
bucketNames: {
images: env.NEXT_PUBLIC_IMAGES_BUCKET_NAME ?? ''
}
} satisfies StorageConfig;7. Run development server
Now you should be able to start the development server:
npm run devTroubleshooting
Connection issues
If you're experiencing connection issues:
- Verify your connection string is correct
- Check that your IP is allowed in Supabase (if IP restrictions are enabled)
- Ensure you're using the correct region
- Try using the direct connection URL instead of the pooled connection
Migration issues
If migrations fail:
- Make sure you're using the direct connection URL for migrations
- Check that your database password is correct
- Verify that your project has the necessary permissions
Storage issues
If file uploads aren't working:
- Verify your S3 credentials are correct
- Check that the bucket exists and is accessible
- Ensure the bucket name matches your configuration
- Verify the endpoint URL is correct
That's all it takes to set up your application with Supabase! If you have questions or need help, refer to the Supabase documentation.