LoginSignup
15
13

More than 3 years have passed since last update.

[Nuxt.js] Firebaseの設定で環境変数dotenvを扱う

Last updated at Posted at 2019-10-13
$ npm i --save @nuxtjs/dotenv
$ yarn add @nuxtjs/dotenv
nuxt.config.js
  plugins: [
    '~/plugins/firebase.js',
  ],
  modules: [
    '@nuxtjs/dotenv',
  ],
plugins/firebase.js
import firebase from "firebase/app";
import "firebase/auth";

if (!firebase.apps.length) {
  firebase.initializeApp({
    apiKey: process.env.API_KEY,
    authDomain: process.env.AUTH_DOMAIN,
    databaseURL: process.env.DATABASE_URL,
    projectId: process.env.PROJECT_ID,
    storageBucket: process.env.STORAGE_BUCKET,
    messagingSenderId: process.env.MESSAGING_SENDER_ID,
    appId: process.env.APP_ID
  })
}

export default firebase;

.envファイル

API_KEY='AIXXXXXXXXXXXXXXXXXXXXXXXX'
AUTH_DOMAIN='hogefuga.firebaseapp.com'
DATABASE_URL='https://hogefuga.firebaseio.com'
PROJECT_ID='hogefugao'
STORAGE_BUCKET='hogefuga.appspot.com'
MESSAGING_SENDER_ID='123456789'
APP_ID='1:123456789:web:abcde1234'

参考

15
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
13