title: Deploying Environment Variables to Vercel with nextjs
body: <p>I am new to next.js and experiencing issues while trying to deploy environment variables to Vercel.</p>
  <p>We are trying to deploy Stripe Payment Gateway to Vercel</p>
  <p>Downloaded the Stripe Payment Gateway Sample code from<br />
  <a href="https://github.com/tmarek-stripe/demo-react-stripe-js" rel="nofollow noreferrer">https://github.com/tmarek-stripe/demo-react-stripe-js</a></p>
  <p>This is a nextjs application with a .env file that has a public and secret key pair.
  Everything works fine while running on localhost , also the projects work fine on Vercel when I include the .env file in the git repository</p>
  <p>As soon as I include the .env file in gitignore and push the updates to the repository , the .env file would not be shown and I get 500 Server error while trying to make test payments</p>
  <p><a href="https://i.stack.imgur.com/PEwCI.png" rel="nofollow noreferrer">Error while making payments</a></p>
  <p><strong>Below is the code for payment intent.js</strong></p>
  <pre><code>import Stripe from &quot;stripe&quot;;
  
  const stripe = new Stripe(process.env.SECRET_KEY);
  
  export default async (req, res) =&gt; {
    if (req.method === &quot;POST&quot;) {
      try {
        const { amount } = req.body;
        
        const paymentIntent = await stripe.paymentIntents.create({
          amount,
          currency: &quot;usd&quot;
        });
  
        res.status(200).send(paymentIntent.client_secret);
      } catch (err) {
        res.status(500).json({ statusCode: 500, message: err.message });
      }
    } else {
      res.setHeader(&quot;Allow&quot;, &quot;POST&quot;);
      res.status(405).end(&quot;Method Not Allowed&quot;);
    }
  };
  </code></pre>
  <p>The .Env File looks like below</p>
  <pre><code>PUBLISHABLE_KEY=pk_test_key
  
  SECRET_KEY=sk_test_Secret Key
  </code></pre>
  <p>Read all the available articles online with no luck.</p>
  <p>No changes were made to the code apart from Public and Secret Key in .env file</p>
  <p>Please let me know how to hide the Environment Variables(as it contains the secret key) and at the same time use it in the production environment</p>
  <p>Any help would be appreciated</p>
  <p>Thanks in Advance</p>