Created
February 27, 2019 09:17
-
-
Save DanielNetzer/e0f46510da13e6a25520de271c6497ca to your computer and use it in GitHub Desktop.
nuxtjs firebase plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import firebase from 'firebase/app' | |
import 'firebase/firestore' | |
import 'firebase/auth' | |
import 'firebase/storage' | |
export default ({ app }, inject) => { | |
const env = process.browser ? app.store.state.env : process.env | |
// init firebase | |
if (!firebase.apps.length && env.API_KEY && env.PROJECT_ID && env.SENDER_ID) { | |
const config = { | |
apiKey: env.API_KEY, | |
authDomain: `${env.PROJECT_ID}.firebaseapp.com`, | |
databaseURL: `https://${env.PROJECT_ID}.firebaseio.com`, | |
projectId: env.PROJECT_ID, | |
storageBucket: `gs://${env.PROJECT_ID}.appspot.com`, | |
messagingSenderId: env.SENDER_ID | |
} | |
firebase.initializeApp(config) | |
} | |
// inject firebase services to application | |
inject('DB', firebase.firestore()) | |
inject('auth', firebase.auth()) | |
inject('storage', firebase.storage()) | |
inject('emailProvider', new firebase.auth.EmailAuthProvider()) | |
inject('firebase', firebase) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment