Learn how to connect Supabase to Vercel with our step-by-step guide. Set up your client, deploy your project and secure your variables.
Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
Step 1: Sign Up for Supabase
Before connecting Supabase to Vercel, you need to have a Supabase account and a project created.
API URL
and anon
key, as you'll need them later.
Step 2: Set Up Supabase Client in Your Vercel App
You need to integrate Supabase with your Vercel application.
npm install @supabase/supabase-js
or
yarn add @supabase/supabase-js
supabaseClient.js
) to configure the Supabase client:import { createClient } from '@supabase/supabase-js';
const supabaseUrl = '<YOUR_SUPABASE_URL>';
const supabaseAnonKey = '<YOUR_SUPABASE_ANON_KEY>';
export const supabase = createClient(supabaseUrl, supabaseAnonKey);
Replace <YOUR_SUPABASE_URL>
and <YOUR_SUPABASE_ANON_KEY>
with your actual Supabase project URL and anon key.
Step 3: Deploy Application to Vercel
Deploy your application to Vercel using either the Vercel CLI or by connecting your GitHub/GitLab repository.
vercel
If you prefer to connect your repository:
Go to Vercel Dashboard.
Click on "New Project" and import your Git repository.
Follow the setup instructions to deploy your application.
Step 4: Set Environment Variables in Vercel
Environment variables store your Supabase credentials securely.
Go to your Vercel Dashboard and click on your newly deployed project.
Navigate to the "Settings" tab.
Under "Environment Variables", add the following:
Key: NEXT_PUBLIC_SUPABASE_URL
Value: <YOUR_SUPABASE_URL>
Key: NEXT_PUBLIC_SUPABASE_ANON_KEY
Value: <YOUR_SUPABASE_ANON_KEY>
Ensure that these variables are matched with those you used in your Supabase client configuration.
Step 5: Verify the Connection
By now, your Vercel app should be connected to Supabase.
import { supabase } from './supabaseClient';
const fetchData = async () => {
const { data, error } = await supabase
.from('your_table_name')
.select('*');
if (error) console.log('Error:', error);
else console.log('Data:', data);
};
fetchData();
Modify 'your_table_name'
to an actual table in your Supabase database.
By following these steps, you should have successfully connected Supabase to your Vercel project. Always ensure your connection credentials remain secure and never push them to a public repository.
When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.