DEV Community

Question with Vue and Firebase

Bos Eriko Reyes on May 26, 2019

Has anyone used Vue with Firebase here? What's the best way to pass the Firebase object around components?

Collapse
 
midblue profile image
Jasper Stephenson

I always have my firebase db actions handled in the vuex store! That way, you never have to directly manipulate the firebase object inside a component, instead you can just call this.$store.commit('updateXProperty', value) to send your mutations to a centralized source. It makes debugging easier, and database updates safer since you can add your own data validation in the store that'll be applied to all updates throughout your app.

In fact, I often split all firebase actions out into their own file that I simply import once in the vuex store, just to further separate different tasks.

Collapse
 
boseriko profile image
Bos Eriko Reyes

Thanks for the tip, Jasper! I asked on the Vue Discord as well and they said I should check VueFire.

Another question, though. How about the authentication? Do you use Vuex for it as well?

Collapse
 
midblue profile image
Jasper Stephenson • Edited

I'd definitely rely on the vue discord's advice, as they're much more the authority than I am :)

I usually use dotenv for my credentials, which is just imported in my database handling file, which handles credentials for my database.

Collapse
 
drozerah profile image
Drozerah