I'm trying to connect Nuxt 2.14 with firebase firestore
I'm writing a plugin for firebase that runs on the server
I'm using "inject" to pass firebase.firestore() object as db.
But, when I'm using the $db I just injected
and try to make a data variable equal to $db via asyncData,
I get an error:
"Maximum call stack size exceeded"
I guess the firebase.firestore() object has a "circular structure"
Any suggestions?
Should I approach this differently?
Thank you
Here is the code for the different files I'm using:
.env
FB_DB_PATH=XXXXXX
FB_API_KEY=YYYYYY
FB_PROJECT_ID=ZZZZZZ
FB_AUTH_DOMAIN=EEEEEEE
nuxt.config.js
plugins: [
{ src: '~plugins/firebase.js', mode: 'server' },
// runs on server to get the firebase privateRuntimeConfig params
],
publicRuntimeConfig: {
baseURL: process.env.BASE_URL // just for test
},
privateRuntimeConfig: {
fbProjectID: process.env.FB_PROJECT_ID,
fbDBPath: process.env.FB_DB_PATH,
fbApiKey: process.env.FB_API_KEY,
fbAuthDomain: process.env.FB_AUTH_DOMAIN
},
firebase.js - this is the plugin file
import firebase from 'firebase/app';
import 'firebase/auth';
import 'firebase/firestore';
export default function (context, inject) {
if (!firebase.apps.length) {
firebase.initializeApp({
apiKey: context.$config.fbApiKey,
authDomain: context.$config.fbAuthDomain,
//databaseURL: context.$config.fbDBPath,
projectId: context.$config.fbProjectID
})
}
let auth = firebase.auth();
let db = firebase.firestore();
inject('db', db);
}
in page code:
asyncData ( context ) {
return { db: context.$db }
}