Quantcast
Channel: Active questions tagged rest - Stack Overflow
Viewing all articles
Browse latest Browse all 3619

Environment Variable "API_SECRET" on Vercel Deployment Issue

$
0
0

I'm encountering an issue with environment variables (API_SECRET) when deploying my Node.js application to Vercel. Despite adding the environment variables correctly, the application fails to recognize API_SECRET during deployment.

Folder Structure:

project-root/│├── .env├── firebase.js├── server/│├── controllers/││├── createVirtualAccount.js││├── handlePaymentNotification.js││└── ...│├── routes/││├── routes.js││└── ...│└── index.js└── package.json

Deployment Platform: VercelNode.js Version: 20.14.0Framework/Libraries: Node.js, Express (if applicable)

Code Snippet (createVirtualAccount.js):

import fetch from 'node-fetch';import dotenv from 'dotenv';dotenv.config();const apiKey = process.env.API_KEY;const apiSecret = process.env.API_SECRET;export const createVirtualAccount = async (req, res, next) => {    try {        if (!apiKey || !apiSecret) {            throw new Error('API_KEY or API_SECRET is missing');        }        const { email, name, phoneNumber, bankcode, account_type, businessid, bvn } = req.body;        const options = {            method: "POST",            body: JSON.stringify({                email,                name,                phoneNumber,                bankcode,                account_type,                businessid,                bvn            }),            headers: {'api-key': apiKey,'api-secret': `Bearer ${apiSecret}`,'Content-Type': 'application/json'            }        };        const apiResponse = await fetch('https://api.payvessel.com/api/external/request/customerReservedAccount', options);        if (!apiResponse.ok) {            const errorText = await apiResponse.json();            throw new Error(`Error: ${apiResponse.status} - ${errorText}`);        }        const data = await apiResponse.json();        res.status(201).json(data);    } catch (error) {        next(error);    }};

I have verified that the .env file is correctly formatted and the environment variables are accessed using dotenv.config().Despite adding API_SECRET to both my local .env file and Vercel environment variables, the application fails to recognize API_SECRET during deployment on Vercel.

Desired Outcome:I'm looking for guidance on how to troubleshoot and resolve the issue with API_SECRET not being recognized during deployment on Vercel. Any suggestions or insights into potential causes or debugging steps would be greatly appreciated.


Viewing all articles
Browse latest Browse all 3619

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>