Skip to content

How to Handle Passwords in a Vue Project

andy.rothwell edited this page Apr 10, 2019 · 11 revisions

.env.local

If you work for the City of Philadelphia, you can add Cyclomedia and Pictometry widgets to your mapboard (or layerboard) app.

These widgets require passwords for those services to be passed within your code. You can't put the City of Philadelphia's passwords for these services directly into your code and push it up to Github however.

To get hidden passwords into your project, create a file at the base of your project called .env.local

If you check your .gitignore file, .env.local should already be in it automatically. If it is not, add it to the .gitignore

In your .env.local file, add passwords like this (with no spaces, quotes, or semi-colons):

VUE_APP_CYCLOMEDIA_API_KEY=*your-api-key*
VUE_APP_CYCLOMEDIA_PASSWORD=*your-password*
VUE_APP_CYCLOMEDIA_USERNAME=*your-username*
VUE_APP_PICTOMETRY_API_KEY=*your-api-key*
VUE_APP_PICTOMETRY_SECRET_KEY=*your-secret-key*

They have to start "VUE_APP_...", or they won't be available in your code.

As long as they do start that way, the passwords will be available anywhere in your vue code as:

process.env.VUE_APP_CYCLOMEDIA_API_KEY
process.env.VUE_APP_CYCLOMEDIA_PASSWORD...

Vue's instructions for this are here: https://cli.vuejs.org/guide/mode-and-env.html#environment-variables

Travis

If you are using Travis to push the files to Amazon S3, it will only have access to files that are in Github.

Since .env.local can't be put into Github, this will break the process which gets the passwords into your code.

The way to fix this is to also put passwords into Travis' Environmental Variables. You have to use the same long names that start with "VUE_APP_...":

Clone this wiki locally