LoginSignup
89
65

More than 5 years have passed since last update.

Firebaseにおける環境変数の設定方法

Last updated at Posted at 2017-09-16

Firebaseでの環境変数のまとめ

FirebaseではAPIのキーなど外部に公開したくない情報を環境変数として、設定することができる。印象としてはherokuなどのように簡単に設定することができて便利。

ほとんど公式ドキュメントに書いてあることだが、備忘録も兼ねて残しておく
追記
Firebase公式ドキュメント | 環境の設定

手順

  • firebaseにログイン
firebase login
  • 設定したいfirebaseプロジェクトまで移動
cd ~/workplace/hoge-projects
  • 環境変数のセット
firebase functions:config:set gmail.email="youremail@gmail.com" gmail.password="yourpassword"
  • 設定した環境変数をチェック
firebase functions:config:get

設定した環境変数の一覧が以下のように見ることができる。

{
  "gmail": {
    "password": "yourpassword",
    "email": "youremail@gmail.com"
  }
}
  • Cloud Functionsなどで環境変数を参照する場合

環境変数にはfunctions.config()でアクセスできる。
あとは自分で設定したプロパティを指定することで取り出すことができる。

index.js
const gmailEmail = encodeURIComponent(functions.config().gmail.email);
const gmailPassword = encodeURIComponent(functions.config().gmail.password);

最後に

firebaseの場合、api keyやapp IDをコピペすることがあり、これも環境変数で扱った方が良いのでは?と思ったのだが、このような記事を見つけた。

この内容によると
スクリーンショット 2017-09-16 19.16.14.png

google apisの認証情報で個別のFirebaseプロジェクトの認証情報が漏れないかぎり不正な利用はされないとのこと。

89
65
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
89
65