Skip to content

Commit

Permalink
Change how to use firebase account env var
Browse files Browse the repository at this point in the history
  • Loading branch information
Augsorn Chanklad committed Feb 27, 2019
1 parent 1ffce95 commit f669c6d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,4 @@ typings/
.next

package-lock.json
serviceAccountKey.json
19 changes: 5 additions & 14 deletions src/firebase.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
const admin = require('firebase-admin');
const fs = require('fs');

// For local development
// var serviceAccount = require('./../serviceAccountKey.json');

// For host environment variable
var serviceAccount = {
"type": "service_account",
"project_id": "kafra-line",
"private_key_id": process.env.FIREBASE_PRIVATE_KEY_ID,
"private_key": process.env.FIREBASE_PRIVATE_KEY,
"client_email": process.env.FIREBASE_CLIENT_EMAIL,
"client_id": process.env.FIREBASE_CLIENT_ID,
"auth_uri": process.env.FIREBASE_AUTH_URI,
"token_uri": process.env.FIREBASE_TOKEN_URI,
"auth_provider_x509_cert_url": process.env.FIREBASE_AUTH_PROVIDER,
"client_x509_cert_url": process.env.FIREBASE_CLIENT_CERT
}

const keysEnvVar = process.env['FIREBASE_ACCOUNT'];
if (!keysEnvVar) {
throw new Error('The $FIREBASE_ACCOUNT environment variable was not found!');
}
var serviceAccount = JSON.parse(keysEnvVar);

admin.initializeApp({
credential: admin.credential.cert(serviceAccount)
Expand Down

0 comments on commit f669c6d

Please sign in to comment.