0

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*******************************'
delfincortesb
  • 85
  • 1
  • 6

3 Answers3

2

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.

linusw
  • 1,140
  • 3
  • 9
0
  • 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

Yasir Ali
  • 111
  • 1
  • 6
0

I was running into a very similar problem getting my Next.js React app to see my Supabase URL and KEY in my .env file. My fix was to add NEXT_PUBLIC_ to the beginning of the variables in the .env file and in CreateClient()

In .env:

NEXT_PUBLIC_REACT_APP_SUPABASE_URL = https://asdf.supabase.co
NEXT_PUBLIC_REACT_APP_SUPABASE_API_KEY = asdfas.asdfasdfsdfasdf

In the CreateClient()

const supabase = createClient(
  process.env.NEXT_PUBLIC_REACT_APP_SUPABASE_URL,
  process.env.NEXT_PUBLIC_REACT_APP_SUPABASE_API_KEY
);
C.RU
  • 1
  • 1