This project will help you get listed on Vercel's marketplace. to gain more visibility for your product.
This project demonstrates how to create a custom Vercel integration that allows users to authorize access to their Vercel account, select a project, and create environment variables for that project using OAuth 2.0 authentication. By providing a seamless integration with Vercel, this project showcases the ability to interact with Vercel's API, empowering developers to enhance their continuous deployment workflows.
This Vercel integration project offers the following key features:
- OAuth 2.0 Authentication with Vercel: Securely authorize access to the user's Vercel account to access project details.
- Project Listing: Fetches and displays the user's Vercel projects, making it easy to select the desired project for further actions.
- Create Environment Variables: Allows the creation of environment variables for the selected Vercel project, aiding in secure handling of sensitive information.
- Secure Data Management: Utilizes environment variables to handle sensitive information, ensuring data security and best practices in managing API keys and secrets.
Integrating with Vercel using OAuth provides a robust way to automate and manage continuous deployment workflows, environment configurations, and other project settings directly from your own applications. This project can be a reference for developers looking to build integrations with Vercel’s API for tasks like managing projects, deploying static sites, and configuring build settings.
Before you start, ensure you have the following:
- Node.js (version 14 or later) and npm or yarn for package management.
- A Vercel account with access to manage projects and integrations.
- A registered Vercel integration (OAuth app) to enable the OAuth 2.0 flow.
Follow these steps to set up and run the Vercel integration project locally:
-
Clone this Repository:
git clone https://github.com/SuprSend-NotificationAPI/Demo-vercel-integration-for-listing-on-their-marketplace.git cd vercel-integration-project
-
Install Dependencies:
npm install
This will install all necessary Node.js modules required to run the project.
-
Create an Environment File: Create a
.env.local
file in the root directory of your project with the following content:VERCEL_CLIENT_ID=your_client_id VERCEL_CLIENT_SECRET=your_client_secret REDIRECT_URI=http://localhost:3000/signup
Replace
your_client_id
andyour_client_secret
with the credentials of your registered Vercel OAuth app. -
Start the Development Server:
npm run dev
This will start the server on
http://localhost:3000
. Open this URL in your browser to access the application.
- The user initiates the OAuth flow by clicking on the authorization link provided by the application.
- Upon successful authorization, the user is redirected back to the application, where the authorization code is exchanged for an access token.
- The access token is then used to interact with the Vercel API to fetch the user's projects.
- The user selects a project, and the application creates an environment variable for that project using the Vercel API.
This workflow demonstrates how to securely integrate with Vercel, offering a scalable way to manage projects, environments, and other settings programmatically.
To create a custom Vercel integration for your own projects, follow these steps:
-
Register a New OAuth App:
- Go to your Vercel account settings and register a new OAuth app.
- Set the redirect URI to
http://localhost:3000/signup
for local development.
-
Configure Your Project:
- Copy the Client ID and Client Secret from the OAuth app to your
.env.local
file. - Modify the
app/signup/page.tsx
component to customize the integration flow as per your requirements.
- Copy the Client ID and Client Secret from the OAuth app to your
-
Extend Integration Features:
- Edit the
app/api/create-env-variable/route.ts
file to handle other actions with the Vercel API, such as creating multiple environment variables, fetching deployment status, or configuring custom build settings.
- Edit the
app/signup/page.tsx
: This is the main component that manages the integration flow, including the OAuth authorization and project selection.app/api/authorize/route.ts
: This file handles the OAuth token exchange, securing the process of obtaining access to the Vercel API.app/api/create-env-variable/route.ts
: Manages the creation of environment variables for the selected Vercel project.
To deploy this application to Vercel:
-
Push Your Code to GitHub:
git push origin main
-
Create a New Vercel Project:
- Go to Vercel, create a new project, and link it to your GitHub repository.
-
Add Environment Variables:
- In the Vercel project settings, add the environment variables from your
.env.local
file for secure handling during deployment.
- In the Vercel project settings, add the environment variables from your
-
Deploy:
- Once set up, deploy the application using Vercel's deployment flow.
- Environment Variables: Always use environment variables to store sensitive information like API keys and secrets. Never commit your
.env.local
file to source control. - OAuth Best Practices: Use proper OAuth flows and token handling to ensure secure API interactions.
- Error Handling: Implement robust error handling and input validation to manage different scenarios and ensure application security in production environments.
Contributions to this Vercel integration project are welcome! Please feel free to fork the repository, make your changes, and submit a Pull Request. Whether it's adding new features, fixing bugs, or improving documentation, your input is valuable.
This project is open source and available under the MIT License.