12
votes

When using firebase or react-native-google-places-autocomplete, I need to supply an api key. Obviously, I can't use a native api key, as the calls are made using web clients. So I have to use a web api key. The problem is, I can't get it to be restricted in google console, because I have no referrer or IP address. Is there any way to solve this?

2
did you find any solutions for this? - vignesh
No. There's also a discussion in the component's repo.. No solution so far.. github.com/FaridSafi/react-native-google-places-autocomplete/… - atlanteh

2 Answers

2
votes

You cannot create a "restricted" key for react-native-google-places-autocomplete, because it does not use the native SDKs. The only API key protection the is available, is to restrict the Google APIs that the key can use (e.g. Google Places, Geocode).

Even though it is not difficult to reverse engineer or check the network calls in a React Native App (or any app for that matter), the key is not out in the open like it would be on a website, where you can just open the dev tools and see the key). If you are concerned about someone using the key, I would recommend sending the api key on app startup, so that if the key were compromised you can swap out the key.

As mentioned in one of the other answers, react-native-google-places uses the native Google Maps SDKs, and therefore it should be possible to use a restricted key with it.

Full disclosure: I am the current maintainer of react-native-google-places-autocomplete.

0
votes

They use native Google SDKs. So it might work for you. https://github.com/tolu360/react-native-google-places

They don't support the new sessionToken based requests. For that, you can refer to this fork. https://github.com/OrangeDigitalAustralia/react-native-google-places