Search code examples
javascriptreactjsvisual-studio-codenetlify

Updating API key on GitHub and Netlify


This is my code github link: https://github.com/Spale96/WeatherApi

I have changed my API key inside my VScode, but netlify still uses old API key even after I have added environment variable inside with new API key.

My question is how to update API key on github and netlify?

I have added environment variable with new API key on netlify but it doesn't update at all.

Netlify still use wrong api which i have deleted

Netlify env added(https://i.sstatic.net/5KzGQ.png)


Solution

  • Updating API Key on GitHub:

    • Open your code in Visual Studio Code (VS Code).
    • Make sure you've updated the API key in your local codebase.
    • Commit the changes to your local Git repository:
    git add .
    git commit -m "Updated API key"
    
    • Push the changes to your GitHub repository:
    git push origin main
    
    

    Updating API Key on Netlify:

    • Log in to your Netlify account.
    • Navigate to your site's dashboard.
    • Go to "Settings" or "Site settings" (the exact wording might vary).
    • Look for an option to set environment variables.
    • Add a new environment variable with the updated API key.
    • Save the changes.

    Make sure you're updating the environment variable for the correct site if you have multiple sites on Netlify.

    If you've already set the environment variable on Netlify and it's not updating, you might need to trigger a redeployment of your site for the changes to take effect. Netlify doesn't automatically update environment variables for existing deployments. Here's how you can trigger a redeployment:

    In your Netlify dashboard, go to the "Deploys" section for your site.

    • Click on the "Trigger deploy" button (or similar) to manually initiate a new deployment.
    • After completing these steps, your updated API key should be in effect both on GitHub and on Netlify.