Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I store Google Maps API keys not using app.json?

I have to store my Google Maps API Key in a safe way (not a commited file), but as i'm using Expo, the Google Maps API key is stored in app.json file, as the following example:

    "ios": {
      "config": {
        "googleMapsApiKey": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
      }
    },
    "android": {
      "config": {
        "googleMaps": {
          "apiKey": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
        }
      }
    }

The problem is, as my app.json file should be commited, where should I store those keys?

like image 354
Marcelo Wippel Avatar asked Jun 17 '19 16:06

Marcelo Wippel


1 Answers

Store them in a .env file like this GOOGLE_API_KEY=yourKey.
Then import to to files as needed with react-native-dotenv package; import { GOOGLE_API_KEY } from 'react-native-dotenv'
The .env file is also never committed to Github.

Also, a good idea to check the AndroidManifest.xml file to make sure the key has not been exposed there.

like image 95
SHG21 Avatar answered Nov 15 '22 03:11

SHG21