我正在尝试从Nuxt Config文件中分离Firebase Creds。但是这就是说NuxtServerError Your API key is invalid,please check you have copied it correctly.
,当我直接将凭据直接用于我的nuxt配置时(没有环境变量),它可以很好地工作。
我正在使用@ nuxtjs / firebase模块,这是我的配置:firebase ssr/universal auth documentation
modules: [
// Doc: https://axios.nuxtjs.org/usage
'@nuxtjs/axios',// Doc: https://github.com/nuxt-community/dotenv-module
'@nuxtjs/dotenv','@nuxtjs/firebase','@nuxtjs/pwa',],firebase: {
config: {
apiKey: process.env.apiKey,authDomain: process.env.authDomain,databaseURL: process.env.databaseURL,projectId: process.env.projectId,storageBucket: process.env.storageBucket,messagingSenderId: process.env.messagingSenderId,appId: process.env.appId,measurementId: process.env.measurementId
},services: {
auth: {
ssr: true
}
}
},pwa: {
// disable the modules you don't need
meta: false,icon: false,// if you omit a module key form configuration sensible defaults will be applied
// manifest: false,workbox: {
importScripts: [
// ...
'/firebase-auth-sw.js'
],// by default the workbox module will not install the service worker in dev environment to avoid conflicts with HMR
// only set this true for testing and remember to always clear your browser cache in development
dev: false
}
}
我已将所有凭据存储在应用程序中的.env
文件中(带引号)。
apiKey="my_key"
authDomain="my_domain"
databaseURL="my_db_url"
projectId="my_project_id"
storageBucket="my_storage_bucket"
messagingSenderId="my_sender_id"
appId="my_app_id"
measurementId="my_measurement_id"
有什么办法可以将我的信誉与nuxt配置文件分开(我将我的nuxt配置文件提交到我的github上)。
PS:我的环境变量可以使用process.env.apikey
等从我的应用程序组件中进行控制台记录。我还安装了@ nuxtjs / dotenv软件包。