Skip to content

Commit

Permalink
fix: alterando para variaveis de ambiente
Browse files Browse the repository at this point in the history
  • Loading branch information
Tacio Medeiros committed Sep 21, 2023
1 parent be74b3f commit 1306eae
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
NEXT_PUBLIC_SITE_URL=http://localhost:3000
FIREBASE_CONFIG=
FIREBASE_CONFIG=
FIREBASE_SERVICE_ACCOUNT=
11 changes: 10 additions & 1 deletion src/utils/db/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import admin from 'firebase-admin';
const serviceAccount = require('../../../serviceAccount.json');
//const serviceAccount = require('../../../serviceAccount.json');

interface Database extends admin.firestore.Firestore {
}

let db: Database;
if (!admin.apps.length) {
//const adminConfig = serviceAccount;

if (!process.env.FIREBASE_SERVICE_ACCOUNT) {
throw new Error('FIREBASE_SERVICE_ACCOUNT is not defined');
}

const serviceAccountString = Buffer.from(process.env.FIREBASE_SERVICE_ACCOUNT, 'base64').toString()
const serviceAccount = JSON.parse(serviceAccountString);

const adminConfig = serviceAccount;
adminConfig.credential = admin.credential.cert(serviceAccount);
admin.initializeApp(adminConfig);
Expand Down

0 comments on commit 1306eae

Please sign in to comment.