按照Google Cloud Functions environment variables config instructions中的说明,我使用Firebase CLI为我的开发环境创建了env vars:
Terminal:
> firebase functions:config:set fbconfig.apikey="[VALUE]"
fbconfig.projectid="[VALUE]" fbconfig.storagebucket="[VALUE]"
fbconfig.messageingsenderid="[VALUE]" fbconfig.databaseurl="[VALUE]"
fbconfig.authdomain="[VALUE]"
在我的Vue.js应用程序(运行Nuxt.js)中,当向项目的Firebase Firestore数据库发出请求时,在Firebase初始化文件中使用了以下内容:
// firebaseInit.js
import firebase from 'firebase/app'
import 'firebase/functions'
import 'firebase/firestore'
import 'firebase/auth'
import 'firebase/storage'
// const functions = require('firebase/functions');
const config = {
apiKey: firebase.functions().config().fbconfig.apikey,
authDomain: firebase.functions().config().fbconfig.authdomain,
databaseURL: firebase.functions().config().fbconfig.databaseurl,
projectId: firebase.functions().config().fbconfig.projectid,
storageBucket: firebase.functions().config().fbconfig.storagebucket,
messagingSenderId: firebase.functions().config().fbconfig.messagesenderid
}
firebase.initializeApp(config)
当我对配置值进行硬编码时,一切正常,但是当我尝试通过Firebase函数(例如,使用`firebase.functions()。config()。fbconfig.apikey)引用env变量时,找不到它们,我收到了错误:
Browser Console:
Uncaught FirebaseError {code: "app/no-app", message: "Firebase: No Firebase
App '[DEFAULT]' has been cre…- call Firebase App.initializeApp() (app/no-
app).", name: "[DEFAULT]", stack: "[DEFAULT]: Firebase: No Firebase App
'[DEFAULT]' h…ntext (http://localhost:3000/_nuxt/app.js:4459:9)"}
我花了太多时间在Firebase文档中运行,并相信我正确地遵循了它们,但似乎无法弄清为什么我无法通过该应用程序访问var。
预先感谢您的帮助。