Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle environment variables #15

Merged
merged 5 commits into from
Jan 28, 2018
Merged

Handle environment variables #15

merged 5 commits into from
Jan 28, 2018

Conversation

robbiemccorkell
Copy link
Contributor

@robbiemccorkell robbiemccorkell commented Jan 27, 2018

Adding react-native-config to allow for the use of a .env file to pass environment variables.

There's a few options out there which do similar things. Once example is react-native-dotenv which simply inlines the environment variables using babel, but I couldn't get it, or similar projects to work.

It seems like it's pretty much impossible to hide secrets from app bundles so the right way to do it is to call back to a server which handles any API key you are using. However I can't really see how that doesn't just make the problem worse because then you're opening up a public API anyone could use.

Either way, I think the variables we will be using aren't hugely sensitive. At least initially we will only be using the read-only contentful API key, which doesn't particularly matter if it leaks, and can be revoked if it starts to get spammed.

Anyone have thoughts?

Pre-flight check-list

Before raising a pull request

  • Documentation
  • Unit tests
  • Build passing

Pre-merge check-list

  • Code review (At least one 👍)
  • Tester approved

@robbiemccorkell
Copy link
Contributor Author

It looks like react-native-config reads .env files, but doesn't read environment variables at build time (why would it I guess). This PR now includes a short script to read vars listed in .env.example, collect the appropriate env vars from process.env and generate a .env file. This file is then persisted to the native build steps.

Ready for review.

Copy link
Collaborator

@markholland markholland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to get this figured out, works as expected

@robbiemccorkell
Copy link
Contributor Author

Awesome thanks @markholland

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants