/supabase-tutorials

How to connect Supabase to Vercel?

Learn how to connect Supabase to Vercel with our step-by-step guide. Set up your client, deploy your project and secure your variables.

Matt Graham, CEO of Rapid Developers

Book a call with an Expert

Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.

Book a free No-Code consultation

How to connect Supabase to Vercel?

 

Step 1: Sign Up for Supabase

 

Before connecting Supabase to Vercel, you need to have a Supabase account and a project created.

  1. Go to the Supabase website.
  2. Sign up for an account or log in if you already have one.
  3. After logging in, create a new project. Note the 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.

  • Start by installing the Supabase client in your project. Assuming that you have a JavaScript or TypeScript-based application, use npm or yarn to install the library:
npm install @supabase/supabase-js

or

yarn add @supabase/supabase-js
  • Next, create a file (e.g., 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.

  • If using Vercel CLI, run the following command in the root of your project:
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.

  • Use the Supabase client in your project to perform database operations like fetching data or inserting new records to confirm the connection.
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.

Want to explore opportunities to work with us?

Connect with our team to unlock the full potential of no-code solutions with a no-commitment consultation!

Book a Free Consultation

Client trust and success are our top priorities

When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.

Rapid Dev was an exceptional project management organization and the best development collaborators I've had the pleasure of working with. They do complex work on extremely fast timelines and effectively manage the testing and pre-launch process to deliver the best possible product. I'm extremely impressed with their execution ability.

CPO, Praction - Arkady Sokolov

May 2, 2023

Working with Matt was comparable to having another co-founder on the team, but without the commitment or cost. He has a strategic mindset and willing to change the scope of the project in real time based on the needs of the client. A true strategic thought partner!

Co-Founder, Arc - Donald Muir

Dec 27, 2022

Rapid Dev are 10/10, excellent communicators - the best I've ever encountered in the tech dev space. They always go the extra mile, they genuinely care, they respond quickly, they're flexible, adaptable and their enthusiasm is amazing.

Co-CEO, Grantify - Mat Westergreen-Thorne

Oct 15, 2022

Rapid Dev is an excellent developer for no-code and low-code solutions.
We’ve had great success since launching the platform in November 2023. In a few months, we’ve gained over 1,000 new active users. We’ve also secured several dozen bookings on the platform and seen about 70% new user month-over-month growth since the launch.

Co-Founder, Church Real Estate Marketplace - Emmanuel Brown

May 1, 2024 

Matt’s dedication to executing our vision and his commitment to the project deadline were impressive. 
This was such a specific project, and Matt really delivered. We worked with a really fast turnaround, and he always delivered. The site was a perfect prop for us!

Production Manager, Media Production Company - Samantha Fekete

Sep 23, 2022