Skip to content
Advertisement

How to use Firebase Environment Variables in Nuxt Config

I am trying to separate Firebase Creds from my Nuxt Config file. But it is saying NuxtServerError Your API key is invalid, please check you have copied it correctly. It works fine when I use my creds directly into my nuxt config (without environment variables).

I am using @nuxtjs/firebase module and this is my config: firebase ssr/universal auth documentation

JavaScript

I have stored all my creds in .env file in my app(with the quotations mark).

JavaScript

Is there any way to separate my creds from nuxt config file (I am committing my nuxt config file on my github).

PS: my environment variables can be console logged from my app component using process.env.apikey and others. I also have @nuxtjs/dotenv package installed.

Advertisement

Answer

That is a @nuxtjs/dotenv issue (I think).

Regarding to Using .env file in nuxt.config.js documentation, for that case you should use directly dotenv module instead of @nuxtjs/dotenv.

nuxt.config.ts sample

JavaScript

nuxt.config.js sample

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement