Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to add firebase config variables on webpack vue project

Implementing Firebase auth on my Vue webpack project. Google tells me to add the config to my index.html file.

If you do this and to go an view page source it exposes the api key to public. I am confused as to why google would suggest this.

Where should I position the configuration variables so it would be safe. Somebody said that main.js is not a good idea in production.

Where should I do the following in my Vue website.

var config = {
   apiKey: "<API_KEY>",
   authDomain: "<PROJECT_ID>.firebaseapp.com",
   databaseURL: "https://<DATABASE_NAME>.firebaseio.com",
   projectId: "<PROJECT_ID>",
   storageBucket: "<BUCKET>.appspot.com",
   messagingSenderId: "<SENDER_ID>",
};
firebase.initializeApp(config);
like image 802
KasparTr Avatar asked Dec 19 '25 09:12

KasparTr


1 Answers

You can simply do it in the App.vue

import Firebase from 'firebase'
let config = {
    apiKey: "...",
    authDomain: "...",
    databaseURL: "...",
    storageBucket: "...",
    messagingSenderId: "..."
  };

let app = Firebase.initializeApp(config)
let db = app.database()
let someDataRef = db.ref('dataset')

enter image description here

like image 60
guyromb Avatar answered Dec 21 '25 23:12

guyromb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!