Skip to content

Commit

Permalink
add: .env for api key
Browse files Browse the repository at this point in the history
The `react-native-dotenv` set up did not work where it couldnt find @env like the documentation says to use

Instead used babel-blugin-inline-dotenv described in this stackoverflow post:  https://stackoverflow.com/questions/57060316/environment-variables-in-babel-config-js

This was the `react-native-dotenv` recommended solution that did not work for me facebook/react-native#29351 (comment)
  • Loading branch information
n-buckley committed Jun 22, 2023
1 parent e6db46b commit 173f936
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 9 deletions.
1 change: 1 addition & 0 deletions .env.development
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TEST_KEY='help'
3 changes: 2 additions & 1 deletion App.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const App = () => {
const [loading, setLoading] = useState(true)
const [location, setLocation] = useState(null)
const [error, setError] = useState(null)

useEffect(() => {
;(async () => {
let { status } = await Location.requestForegroundPermissionsAsync()
Expand All @@ -25,6 +24,8 @@ const App = () => {
})()
}, [])

console.log(process.env.TEST_KEY)

if (location) {
console.log(location)
}
Expand Down
30 changes: 26 additions & 4 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
module.exports = function(api) {
api.cache(true);
module.exports = function (api) {
api.cache(true)
return {
presets: ['babel-preset-expo'],
};
};
env: {
production: {
plugins: [
[
'inline-dotenv',
{
path: '.env.production'
}
]
]
},
development: {
plugins: [
[
'inline-dotenv',
{
path: '.env.development'
}
]
]
}
}
}
}
45 changes: 44 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,22 @@
"@react-navigation/bottom-tabs": "^6.5.7",
"@react-navigation/native": "^6.1.6",
"expo": "~48.0.18",
"expo-location": "~15.1.1",
"expo-status-bar": "~1.4.4",
"react": "18.2.0",
"react-native": "0.71.8",
"react-native-safe-area-context": "4.5.0",
"react-native-screens": "~3.20.0",
"expo-location": "~15.1.1"
"react-native-screens": "~3.20.0"
},
"devDependencies": {
"@babel/core": "^7.20.0",
"@react-native-community/eslint-config": "^3.2.0",
"babel-plugin-inline-dotenv": "^1.7.0",
"eslint": "^8.43.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-react": "^7.32.2",
"prettier": "2.8.8"
"prettier": "2.8.8",
"react-native-dotenv": "^3.4.9"
},
"private": true
}

0 comments on commit 173f936

Please sign in to comment.