skip to Main Content

I am using EXPO 49 so According to the documentation I must create a .env file and use this format: EXPO_PUBLIC_[NAME]=VALUE and then I will be able to use env variables in my code with this format: process.env.EXPO_PUBLIC_[NAME]=VALUE.

The thing is I am getting Undefined and I followed all the steps correctly.

this is my .env file:

EXPO_PUBLIC_APIKEY=secretword

this is my screen code:

import React, { useState } from 'react'
import { Image, Text, TextInput, TouchableOpacity, View } from 'react-native'
//import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view';
import styles from './styles';
import { createUserWithEmailAndPassword } from "firebase/auth";
import { FIREBASE_AUTH } from '../../../firebaseConfig';


export default function RegistrationScreen({ navigation }) {
  const [fullName, setFullName] = useState('')
  const [email, setEmail] = useState('')
  const [password, setPassword] = useState('')
  const [confirmPassword, setConfirmPassword] = useState('')
  
  const onFooterLinkPress = () => {
    navigation.navigate('Login')
  }
  
  const onRegisterPress = () => {
    const apiurl = process.env.EXPO_PUBLIC_APIKEY;
    console.log(apiurl)
  }

2

Answers


  1. Chosen as BEST ANSWER

    I solved the problem. The problem was the name of the .env file it was "keys.env", then I renamed it to ".env" and now all work fine.


  2. I am having the same problem even with the correct naming, I still get undefined, I tried using .env.local, it still didn’t work

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search