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*******************************'
CodePudding user response:
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.
CodePudding user response:
- Step 1 - install dotenv
npm install dotenv
- Step 2 - create a file with no name but with
.env
extension in the root directory - Step 3 - import 'dotenv/config' (ES6 Syntax)
the problem in your case seems to be that you are not importing dotenv/config
and your file name is database.env which is not correct, just name it as .env