PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, August 19, 2022

[FIXED] Why is my env variable showing up as undefined?

 August 19, 2022     environment-variables, javascript, reactjs, supabase, supabase-database     No comments   

Issue

I'm trying to get data from a table with Supabase. When I try store the URL and the Key on a .env file it comes back as undefined.

File: App.js

import React, { useEffect } from "react";
import ButtonsSection from "./ButtonsSection";
import Header from "./Header";
import InputsSection from "./InputsSection";
import ResultsSection from "./ResultsSection";

export default function App() {
  useEffect(() => {
    console.log(process.env.REACT_APP_SUPABASE_URL);
  }, []);

  return (
    <div>
      <Header />
      <InputsSection />
      <ButtonsSection />
      <ResultsSection />
    </div>
  );
}

File: Database.env

REACT_APP_SUPABASE_URL='https://**********.supabase.co'
REACT_APP_SUPABASE_ANON_KEY='***************.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InF2bW56a2xka25hZG1wcmZtc3JqIiwicm9sZSI6ImFub24iLCJpYXQiOjE2NTU0MDQ4NDQsImV4cCI6MTk3MDk4MDg0NH0.Th_x*******************************'

Solution

assuming you are using create-react-app. File name should be ".env" not "Database.env" and it should be in the root folder of the project.



Answered By - linusw
Answer Checked By - Pedro (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing